BitOps

Usage

use BitOps;

or

import BitOps;

Bitwise operations implemented using C intrinsics when possible.

proc clz(x: integral)

Count leading zeros in x.

Returns

the number of 0 bits before the most significant 1 bit in x

Return type

x.type

proc ctz(x: integral)

Count trailing zeros in x.

Returns

the number of 0 bits after the least significant 1 bit in x

Return type

x.type

proc popcount(x: integral)

Find the population count of x.

Returns

the number of 1 bits set in x as x.type

Return type

x.type

proc parity(x: integral)

Find the parity of x.

Returns

  • 0 – when an even number of bits are set in x

  • 1 – when an odd number of bits are set in x

Return type

x.type

proc rotl(x: integral, n: integral)

Rotate x left.

Arguments
  • x – integral of size bits

  • n – rotation amount, must be less than bits

Returns

x rotated left by n bits

Return type

x.type

proc rotr(x: integral, n: integral)

Rotate x right.

Arguments
  • x – integral of size bits

  • n – rotation amount, must be less than bits

Returns

x rotated right by n bits

Return type

x.type