parent
ede0651741
commit
7d2790fdf4
|
@ -302,7 +302,7 @@ func countOnes*(x: SomeUnsignedInt): int {.inline.} =
|
|||
countOnesNim(x)
|
||||
|
||||
func countZeros*(x: SomeUnsignedInt): int {.inline.} =
|
||||
sizeof(x) - countOnes(x)
|
||||
bitsof(x) - countOnes(x)
|
||||
|
||||
func parity*(x: SomeUnsignedInt): int {.inline.} =
|
||||
## Calculate the bit parity in integer. If number of 1-bit
|
||||
|
|
|
@ -11,6 +11,10 @@ template test() =
|
|||
doAssert countOnes(0b11111111'u64) == 8
|
||||
doAssert countOnes(0b11000001'u) == 3
|
||||
|
||||
doAssert countZeros(0b00000000'u8) == 8
|
||||
doAssert countZeros(0b01000100'u8) == 6
|
||||
doAssert countZeros(0b11111111'u64) == 56
|
||||
|
||||
doAssert firstOne(0b00000000'u8) == 0
|
||||
doAssert firstOne(0b00000001'u64) == 1
|
||||
doAssert firstOne(0b00010010'u8) == 2
|
||||
|
@ -141,4 +145,3 @@ suite "bitops2":
|
|||
test "bitops2_test":
|
||||
test() # Cannot use unittest at compile time..
|
||||
runtimeTest()
|
||||
|
||||
|
|
Loading…
Reference in New Issue