Added bitops2.bitWidth

This commit is contained in:
Zahary Karadjov 2019-07-31 02:00:39 +03:00
parent ff326d686c
commit 81cbc16f15
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 5 additions and 0 deletions

View File

@ -346,6 +346,11 @@ func log2trunc*(x: SomeUnsignedInt): int {.inline.} =
else:
log2truncNim(x)
template bitWidth*(x: SomeUnsignedInt): int =
## Returns the number of bits needed to write down the
## number `x` in binary. If `x` is zero, the result is 0.
log2trunc(x) + 1
func leadingZeros*(x: SomeInteger): int {.inline.} =
## Returns the number of leading zero bits in integer.
## If `x` is zero, result is bitsof(x)