...

# Package bits

`import "math/bits"`
Overview
Index
Examples

## Overview ▾

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

## Constants

UintSize is the size of a uint in bits.

`const UintSize = uintSize`

`func LeadingZeros(x uint) int`

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

`func LeadingZeros16(x uint16) int`

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

Example

```16
15
7
0
```

`func LeadingZeros32(x uint32) int`

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

Example

```32
31
```

`func LeadingZeros64(x uint64) int`

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

Example

```64
63
```

`func LeadingZeros8(x uint8) int`

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

## func Len¶

`func Len(x uint) int`

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

## func Len16¶

`func Len16(x uint16) (n int)`

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

## func Len32¶

`func Len32(x uint32) (n int)`

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

## func Len64¶

`func Len64(x uint64) (n int)`

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

## func Len8¶

`func Len8(x uint8) int`

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

## func OnesCount¶

`func OnesCount(x uint) int`

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

Example

```1110
3
```

## func OnesCount16¶

`func OnesCount16(x uint16) int`

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

Example

```1110
3
```

## func OnesCount32¶

`func OnesCount32(x uint32) int`

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

Example

```1110
3
```

## func OnesCount64¶

`func OnesCount64(x uint64) int`

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

Example

```1110
3
```

## func OnesCount8¶

`func OnesCount8(x uint8) int`

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

Example

```1110
3
```

## func Reverse¶

`func Reverse(x uint) uint`

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

## func Reverse16¶

`func Reverse16(x uint16) uint16`

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

## func Reverse32¶

`func Reverse32(x uint32) uint32`

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

## func Reverse64¶

`func Reverse64(x uint64) uint64`

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

## func Reverse8¶

`func Reverse8(x uint8) uint8`

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

## func ReverseBytes¶

`func ReverseBytes(x uint) uint`

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

## func ReverseBytes16¶

`func ReverseBytes16(x uint16) uint16`

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

## func ReverseBytes32¶

`func ReverseBytes32(x uint32) uint32`

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

## func ReverseBytes64¶

`func ReverseBytes64(x uint64) uint64`

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

## func RotateLeft¶

`func RotateLeft(x uint, k int) uint`

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

## func RotateLeft16¶

`func RotateLeft16(x uint16, k int) uint16`

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

## func RotateLeft32¶

`func RotateLeft32(x uint32, k int) uint32`

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

## func RotateLeft64¶

`func RotateLeft64(x uint64, k int) uint64`

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

## func RotateLeft8¶

`func RotateLeft8(x uint8, k int) uint8`

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

## func TrailingZeros¶

`func TrailingZeros(x uint) int`

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

## func TrailingZeros16¶

`func TrailingZeros16(x uint16) (n int)`

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

## func TrailingZeros32¶

`func TrailingZeros32(x uint32) int`

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

## func TrailingZeros64¶

`func TrailingZeros64(x uint64) int`

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

## func TrailingZeros8¶

`func TrailingZeros8(x uint8) int`

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