@@ -111,6 +111,9 @@ proc `&`*(a, b: BitsArray): BitsArray =
111111 for i in 0 || (a.blocks- 1 ):
112112 result .bits[i] = bitand (a.bits[i], b.bits[i])
113113
114+ template bitand * (a, b: BitsArray ): BitsArray =
115+ a & b
116+
114117proc `|` * (a, b: BitsArray ): BitsArray =
115118 # # Computes the bitwise or of a and b.
116119 # #
@@ -120,20 +123,29 @@ proc `|`*(a, b: BitsArray): BitsArray =
120123 for i in 0 || (a.blocks- 1 ):
121124 result .bits[i] = bitor (a.bits[i], b.bits[i])
122125
126+ template bitor * (a, b: BitsArray ): BitsArray =
127+ a | b
128+
123129proc `~` * (a: BitsArray ): BitsArray =
124130 # # Computes the bitwise not of a.
125131 # #
126132 result = newBitsArray (a.len)
127133 for i in 0 || (a.blocks- 1 ):
128134 result .bits[i] = bitnot (a.bits[i])
129135
136+ template bitnot * (a: BitsArray ): BitsArray =
137+ ~ a
138+
130139proc `^` * (a,b : BitsArray ): BitsArray =
131140 # # Computes the bitwise xor of a and b.
132141 # #
133142 result = newBitsArray (a.len)
134143 for i in 0 || (a.blocks- 1 ):
135144 result .bits[i] = bitxor (a.bits[i], b.bits[i])
136145
146+ template bitxor * (a,b : BitsArray ): BitsArray =
147+ a ^ b
148+
137149proc `[]` * (a: BitsArray , loc: int ): bool =
138150 # # Test bit value at loc.
139151 # #
@@ -468,6 +480,7 @@ when isMainModule:
468480 echo " a & b = " , a & b
469481 echo " a | b = " , a | b
470482 echo " a ^ b = " , a ^ b
483+ echo " a bitxor b = " , a.bitxor (b)
471484 echo " ~a = " , ~ a
472485 echo " a.shl(1) =" ,a.shl (1 )
473486 echo " a.shl(2) =" ,a.shl (2 )
0 commit comments