mirror of
https://github.com/status-im/nim-stew.git
synced 2025-02-16 22:17:03 +00:00
Added bitops2.bitWidth
This commit is contained in:
parent
ff326d686c
commit
81cbc16f15
@ -346,6 +346,11 @@ func log2trunc*(x: SomeUnsignedInt): int {.inline.} =
|
|||||||
else:
|
else:
|
||||||
log2truncNim(x)
|
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.} =
|
func leadingZeros*(x: SomeInteger): int {.inline.} =
|
||||||
## Returns the number of leading zero bits in integer.
|
## Returns the number of leading zero bits in integer.
|
||||||
## If `x` is zero, result is bitsof(x)
|
## If `x` is zero, result is bitsof(x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user