Package bits implements bit counting and manipulation functions for the predeclared unsigned integer types.

Functions in this package may be implemented directly by the compiler, for better performance. For those functions the code in this package will not be used. Which functions are implemented by the compiler depends on the architecture and the Go release.

Static methods

staticinlineadd(_x:GoUInt, _y:GoUInt, _carry:GoUInt):{_1:GoUInt, _0:GoUInt}

Add returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.

This function's execution time does not depend on the inputs.

See also:

staticinlineadd32(_x:GoUInt32, _y:GoUInt32, _carry:GoUInt32):{_1:GoUInt32, _0:GoUInt32}

Add32 returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.

This function's execution time does not depend on the inputs.

See also:

staticinlineadd64(_x:GoUInt64, _y:GoUInt64, _carry:GoUInt64):{_1:GoUInt64, _0:GoUInt64}

Add64 returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.

This function's execution time does not depend on the inputs.

See also:

staticinlinediv(_hi:GoUInt, _lo:GoUInt, _y:GoUInt):{_1:GoUInt, _0:GoUInt}

Div returns the quotient and remainder of (hi, lo) divided by y: quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo. Div panics for y == 0 (division by zero) or y <= hi (quotient overflow).

See also:

staticinlinediv32(_hi:GoUInt32, _lo:GoUInt32, _y:GoUInt32):{_1:GoUInt32, _0:GoUInt32}

Div32 returns the quotient and remainder of (hi, lo) divided by y: quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo. Div32 panics for y == 0 (division by zero) or y <= hi (quotient overflow).

See also:

staticinlinediv64(_hi:GoUInt64, _lo:GoUInt64, _y:GoUInt64):{_1:GoUInt64, _0:GoUInt64}

Div64 returns the quotient and remainder of (hi, lo) divided by y: quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo. Div64 panics for y == 0 (division by zero) or y <= hi (quotient overflow).

See also:

staticinlineleadingZeros(_x:GoUInt):GoInt

LeadingZeros returns the number of leading zero bits in x; the result is UintSize for x == 0.

See also:

staticinlineleadingZeros16(_x:GoUInt16):GoInt

LeadingZeros16 returns the number of leading zero bits in x; the result is 16 for x == 0.

See also:

staticinlineleadingZeros32(_x:GoUInt32):GoInt

LeadingZeros32 returns the number of leading zero bits in x; the result is 32 for x == 0.

See also:

staticinlineleadingZeros64(_x:GoUInt64):GoInt

LeadingZeros64 returns the number of leading zero bits in x; the result is 64 for x == 0.

See also:

staticinlineleadingZeros8(_x:GoUInt8):GoInt

LeadingZeros8 returns the number of leading zero bits in x; the result is 8 for x == 0.

See also:

staticinlinelen(_x:GoUInt):GoInt

Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.

See also:

staticinlinelen16(_x:GoUInt16):GoInt

Len16 returns the minimum number of bits required to represent x; the result is 0 for x == 0.

See also:

staticinlinelen32(_x:GoUInt32):GoInt

Len32 returns the minimum number of bits required to represent x; the result is 0 for x == 0.

See also:

staticinlinelen64(_x:GoUInt64):GoInt

Len64 returns the minimum number of bits required to represent x; the result is 0 for x == 0.

See also:

staticinlinelen8(_x:GoUInt8):GoInt

Len8 returns the minimum number of bits required to represent x; the result is 0 for x == 0.

See also:

staticinlinemul(_x:GoUInt, _y:GoUInt):{_1:GoUInt, _0:GoUInt}

Mul returns the full-width product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.

This function's execution time does not depend on the inputs.

See also:

staticinlinemul32(_x:GoUInt32, _y:GoUInt32):{_1:GoUInt32, _0:GoUInt32}

Mul32 returns the 64-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.

This function's execution time does not depend on the inputs.

See also:

staticinlinemul64(_x:GoUInt64, _y:GoUInt64):{_1:GoUInt64, _0:GoUInt64}

Mul64 returns the 128-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.

This function's execution time does not depend on the inputs.

See also:

staticinlineonesCount(_x:GoUInt):GoInt

OnesCount returns the number of one bits ("population count") in x.

See also:

staticinlineonesCount16(_x:GoUInt16):GoInt

OnesCount16 returns the number of one bits ("population count") in x.

See also:

staticinlineonesCount32(_x:GoUInt32):GoInt

OnesCount32 returns the number of one bits ("population count") in x.

See also:

staticinlineonesCount64(_x:GoUInt64):GoInt

OnesCount64 returns the number of one bits ("population count") in x.

See also:

staticinlineonesCount8(_x:GoUInt8):GoInt

OnesCount8 returns the number of one bits ("population count") in x.

See also:

staticinlinerem(_hi:GoUInt, _lo:GoUInt, _y:GoUInt):GoUInt

Rem returns the remainder of (hi, lo) divided by y. Rem panics for y == 0 (division by zero) but, unlike Div, it doesn't panic on a quotient overflow.

See also:

staticinlinerem32(_hi:GoUInt32, _lo:GoUInt32, _y:GoUInt32):GoUInt32

Rem32 returns the remainder of (hi, lo) divided by y. Rem32 panics for y == 0 (division by zero) but, unlike Div32, it doesn't panic on a quotient overflow.

See also:

staticinlinerem64(_hi:GoUInt64, _lo:GoUInt64, _y:GoUInt64):GoUInt64

Rem64 returns the remainder of (hi, lo) divided by y. Rem64 panics for y == 0 (division by zero) but, unlike Div64, it doesn't panic on a quotient overflow.

See also:

staticinlinereverse(_x:GoUInt):GoUInt

Reverse returns the value of x with its bits in reversed order.

See also:

staticinlinereverse16(_x:GoUInt16):GoUInt16

Reverse16 returns the value of x with its bits in reversed order.

See also:

staticinlinereverse32(_x:GoUInt32):GoUInt32

Reverse32 returns the value of x with its bits in reversed order.

See also:

staticinlinereverse64(_x:GoUInt64):GoUInt64

Reverse64 returns the value of x with its bits in reversed order.

See also:

staticinlinereverse8(_x:GoUInt8):GoUInt8

Reverse8 returns the value of x with its bits in reversed order.

See also:

staticinlinereverseBytes(_x:GoUInt):GoUInt

ReverseBytes returns the value of x with its bytes in reversed order.

This function's execution time does not depend on the inputs.

See also:

staticinlinereverseBytes16(_x:GoUInt16):GoUInt16

ReverseBytes16 returns the value of x with its bytes in reversed order.

This function's execution time does not depend on the inputs.

See also:

staticinlinereverseBytes32(_x:GoUInt32):GoUInt32

ReverseBytes32 returns the value of x with its bytes in reversed order.

This function's execution time does not depend on the inputs.

See also:

staticinlinereverseBytes64(_x:GoUInt64):GoUInt64

ReverseBytes64 returns the value of x with its bytes in reversed order.

This function's execution time does not depend on the inputs.

See also:

staticinlinerotateLeft(_x:GoUInt, _k:GoInt):GoUInt

RotateLeft returns the value of x rotated left by (k mod UintSize) bits. To rotate x right by k bits, call RotateLeft(x, -k).

This function's execution time does not depend on the inputs.

See also:

staticinlinerotateLeft16(_x:GoUInt16, _k:GoInt):GoUInt16

RotateLeft16 returns the value of x rotated left by (k mod 16) bits. To rotate x right by k bits, call RotateLeft16(x, -k).

This function's execution time does not depend on the inputs.

See also:

staticinlinerotateLeft32(_x:GoUInt32, _k:GoInt):GoUInt32

RotateLeft32 returns the value of x rotated left by (k mod 32) bits. To rotate x right by k bits, call RotateLeft32(x, -k).

This function's execution time does not depend on the inputs.

See also:

staticinlinerotateLeft64(_x:GoUInt64, _k:GoInt):GoUInt64

RotateLeft64 returns the value of x rotated left by (k mod 64) bits. To rotate x right by k bits, call RotateLeft64(x, -k).

This function's execution time does not depend on the inputs.

See also:

staticinlinerotateLeft8(_x:GoUInt8, _k:GoInt):GoUInt8

RotateLeft8 returns the value of x rotated left by (k mod 8) bits. To rotate x right by k bits, call RotateLeft8(x, -k).

This function's execution time does not depend on the inputs.

See also:

staticinlinesub(_x:GoUInt, _y:GoUInt, _borrow:GoUInt):{_1:GoUInt, _0:GoUInt}

Sub returns the difference of x, y and borrow: diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.

This function's execution time does not depend on the inputs.

See also:

staticinlinesub32(_x:GoUInt32, _y:GoUInt32, _borrow:GoUInt32):{_1:GoUInt32, _0:GoUInt32}

Sub32 returns the difference of x, y and borrow, diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.

This function's execution time does not depend on the inputs.

See also:

staticinlinesub64(_x:GoUInt64, _y:GoUInt64, _borrow:GoUInt64):{_1:GoUInt64, _0:GoUInt64}

Sub64 returns the difference of x, y and borrow: diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.

This function's execution time does not depend on the inputs.

See also:

staticinlinetrailingZeros(_x:GoUInt):GoInt

TrailingZeros returns the number of trailing zero bits in x; the result is UintSize for x == 0.

See also:

staticinlinetrailingZeros16(_x:GoUInt16):GoInt

TrailingZeros16 returns the number of trailing zero bits in x; the result is 16 for x == 0.

See also:

staticinlinetrailingZeros32(_x:GoUInt32):GoInt

TrailingZeros32 returns the number of trailing zero bits in x; the result is 32 for x == 0.

See also:

staticinlinetrailingZeros64(_x:GoUInt64):GoInt

TrailingZeros64 returns the number of trailing zero bits in x; the result is 64 for x == 0.

See also:

staticinlinetrailingZeros8(_x:GoUInt8):GoInt

TrailingZeros8 returns the number of trailing zero bits in x; the result is 8 for x == 0.

See also: