Package bits

import "math/bits"
Overview
Index
Examples

Overview ▾

包位为预声明的无符号整数类型实现位计数和操作功能.

Index ▾

Constants
func Add(x, y, carry uint) (sum, carryOut uint)
func Add32(x, y, carry uint32) (sum, carryOut uint32)
func Add64(x, y, carry uint64) (sum, carryOut uint64)
func Div(hi, lo, y uint) (quo, rem uint)
func Div32(hi, lo, y uint32) (quo, rem uint32)
func Div64(hi, lo, y uint64) (quo, rem uint64)
func LeadingZeros(x uint) int
func LeadingZeros16(x uint16) int
func LeadingZeros32(x uint32) int
func LeadingZeros64(x uint64) int
func LeadingZeros8(x uint8) int
func Len(x uint) int
func Len16(x uint16) (n int)
func Len32(x uint32) (n int)
func Len64(x uint64) (n int)
func Len8(x uint8) int
func Mul(x, y uint) (hi, lo uint)
func Mul32(x, y uint32) (hi, lo uint32)
func Mul64(x, y uint64) (hi, lo uint64)
func OnesCount(x uint) int
func OnesCount16(x uint16) int
func OnesCount32(x uint32) int
func OnesCount64(x uint64) int
func OnesCount8(x uint8) int
func Reverse(x uint) uint
func Reverse16(x uint16) uint16
func Reverse32(x uint32) uint32
func Reverse64(x uint64) uint64
func Reverse8(x uint8) uint8
func ReverseBytes(x uint) uint
func ReverseBytes16(x uint16) uint16
func ReverseBytes32(x uint32) uint32
func ReverseBytes64(x uint64) uint64
func RotateLeft(x uint, k int) uint
func RotateLeft16(x uint16, k int) uint16
func RotateLeft32(x uint32, k int) uint32
func RotateLeft64(x uint64, k int) uint64
func RotateLeft8(x uint8, k int) uint8
func Sub(x, y, borrow uint) (diff, borrowOut uint)
func Sub32(x, y, borrow uint32) (diff, borrowOut uint32)
func Sub64(x, y, borrow uint64) (diff, borrowOut uint64)
func TrailingZeros(x uint) int
func TrailingZeros16(x uint16) int
func TrailingZeros32(x uint32) int
func TrailingZeros64(x uint64) int
func TrailingZeros8(x uint8) int

Package files

bits.go bits_errors.go bits_tables.go

Constants

UintSize是uint的大小(以位为单位).

const UintSize = uintSize

func Add 1.12

func Add(x, y, carry uint) (sum, carryOut uint)

加法返回带有x,y和进位的总和:sum = x + y +进位. 进位输入必须为0或1; 否则,行为是不确定的. 进位输出保证为0或1.

该函数的执行时间不取决于输入.

func Add32 1.12

func Add32(x, y, carry uint32) (sum, carryOut uint32)

Add32返回带有x,y和进位的和:sum = x + y +进位. 进位输入必须为0或1; 否则,行为是不确定的. 进位输出保证为0或1.

该函数的执行时间不取决于输入.

func Add64 1.12

func Add64(x, y, carry uint64) (sum, carryOut uint64)

Add64返回x,y和进位的总和:sum = x + y +进位. 进位输入必须为0或1; 否则,行为是不确定的. 进位输出保证为0或1.

该函数的执行时间不取决于输入.

func Div 1.12

func Div(hi, lo, y uint) (quo, rem uint)

Div返回(hi,lo)的商和余数除以y:quo =(hi,lo)/ y,rem =(hi,lo)%y,其分红位的上半部分为参数hi,下半部分为参数hi参数lo. y == 0(除以零)或y <= hi(商溢出)的除法.

func Div32 1.12

func Div32(hi, lo, y uint32) (quo, rem uint32)

Div32返回(hi,lo)的商和余数除以y:quo =(hi,lo)/ y,rem =(hi,lo)%y,股息位的上半部分在参数hi中,下半部分在参数hi中参数lo. y == 0(除以零)或y <= hi(商溢出)的Div32恐慌.

func Div64 1.12

func Div64(hi, lo, y uint64) (quo, rem uint64)

Div64返回(hi,lo)的商和余数除以y:quo =(hi,lo)/ y,rem =(hi,lo)%y,股息位的上半部分在参数hi中,下半部分在参数hi中参数lo. y == 0(除以零)或y <= hi(商溢出)的Div64恐慌.

func LeadingZeros 1.9

func LeadingZeros(x uint) int

LeadingZeros返回x中前导零位的数量; 结果是x == 0的UintSize.

func LeadingZeros16 1.9

func LeadingZeros16(x uint16) int

LeadingZeros16返回x中前导零位的数目; x == 0的结果是16.

Example

LeadingZeros16(0000000000000001) = 15

func LeadingZeros32 1.9

func LeadingZeros32(x uint32) int

LeadingZeros32返回x中前导零位的数目; x == 0的结果是32.

Example

LeadingZeros32(00000000000000000000000000000001) = 31

func LeadingZeros64 1.9

func LeadingZeros64(x uint64) int

LeadingZeros64返回x中前导零位的数量; x == 0的结果是64.

Example

LeadingZeros64(0000000000000000000000000000000000000000000000000000000000000001) = 63

func LeadingZeros8 1.9

func LeadingZeros8(x uint8) int

LeadingZeros8返回x中前导零位的数量; 对于x == 0,结果为8.

Example

LeadingZeros8(00000001) = 7

func Len 1.9

func Len(x uint) int

Len返回表示x所需的最小位数; x == 0的结果是0.

func Len16 1.9

func Len16(x uint16) (n int)

Len16返回表示x所需的最小位数. x == 0的结果是0.

Example

Len16(0000000000001000) = 4

func Len32 1.9

func Len32(x uint32) (n int)

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

Example

Len32(00000000000000000000000000001000) = 4

func Len64 1.9

func Len64(x uint64) (n int)

Len64返回表示x所需的最小位数. x == 0的结果是0.

Example

Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4

func Len8 1.9

func Len8(x uint8) int

Len8返回表示x所需的最小位数. x == 0的结果是0.

Example

Len8(00001000) = 4

func Mul 1.12

func Mul(x, y uint) (hi, lo uint)

Mul返回x和y的全角乘积:(hi,lo)= x * y,乘积位的上半部返回hi,下半部返回lo.

该函数的执行时间不取决于输入.

func Mul32 1.12

func Mul32(x, y uint32) (hi, lo uint32)

Mul32返回x和y的64位乘积:(hi,lo)= x * y,乘积位的上半部分在hi中返回,而下半部分在lo中返回.

该函数的执行时间不取决于输入.

func Mul64 1.12

func Mul64(x, y uint64) (hi, lo uint64)

Mul64返回x和y的128位乘积:(hi,lo)= x * y,乘积位的上半部返回hi,下半部返回lo.

该函数的执行时间不取决于输入.

func OnesCount 1.9

func OnesCount(x uint) int

OnesCount返回x中的一位数("人口计数").

Example

OnesCount(1110) = 3

func OnesCount16 1.9

func OnesCount16(x uint16) int

OnesCount16返回x中的一位数("人口计数").

Example

OnesCount16(0000000000001110) = 3

func OnesCount32 1.9

func OnesCount32(x uint32) int

OnesCount32返回x中的一位数("人口计数").

Example

OnesCount32(00000000000000000000000000001110) = 3

func OnesCount64 1.9

func OnesCount64(x uint64) int

OnesCount64返回x中的一位数("人口计数").

Example

OnesCount64(0000000000000000000000000000000000000000000000000000000000001110) = 3

func OnesCount8 1.9

func OnesCount8(x uint8) int

OnesCount8返回x中的一位数("人口计数").

Example

OnesCount8(00001110) = 3

func Reverse 1.9

func Reverse(x uint) uint

反向以相反的顺序返回x的值及其位.

func Reverse16 1.9

func Reverse16(x uint16) uint16

Reverse16以相反的顺序返回x的值及其位.

Example

0000000000010011
1100100000000000

func Reverse32 1.9

func Reverse32(x uint32) uint32

Reverse32以相反的顺序返回x的值及其位.

Example

00000000000000000000000000010011
11001000000000000000000000000000

func Reverse64 1.9

func Reverse64(x uint64) uint64

Reverse64以相反的顺序返回x的值及其位.

Example

0000000000000000000000000000000000000000000000000000000000010011
1100100000000000000000000000000000000000000000000000000000000000

func Reverse8 1.9

func Reverse8(x uint8) uint8

Reverse8以相反的顺序返回x的值及其位.

Example

00010011
11001000

func ReverseBytes 1.9

func ReverseBytes(x uint) uint

ReverseBytes以相反的顺序返回x的值及其字节.

该函数的执行时间不取决于输入.

func ReverseBytes16 1.9

func ReverseBytes16(x uint16) uint16

ReverseBytes16以相反的顺序返回x的值及其字节.

该函数的执行时间不取决于输入.

Example

0000000000001111
0000111100000000

func ReverseBytes32 1.9

func ReverseBytes32(x uint32) uint32

ReverseBytes32以相反的顺序返回x的值及其字节.

该函数的执行时间不取决于输入.

Example

00000000000000000000000000001111
00001111000000000000000000000000

func ReverseBytes64 1.9

func ReverseBytes64(x uint64) uint64

ReverseBytes64以相反的顺序返回x的值及其字节.

该函数的执行时间不取决于输入.

Example

0000000000000000000000000000000000000000000000000000000000001111
0000111100000000000000000000000000000000000000000000000000000000

func RotateLeft 1.9

func RotateLeft(x uint, k int) uint

RotateLeft返回向左旋转(k mod UintSize)位的x的值. 要向右旋转k位,请调用RotateLeft(x,-k).

该函数的执行时间不取决于输入.

func RotateLeft16 1.9

func RotateLeft16(x uint16, k int) uint16

RotateLeft16返回向左旋转(k mod 16)位的x的值. 要向右旋转k位,请调用RotateLeft16(x,-k).

该函数的执行时间不取决于输入.

Example

0000000000001111
0000000000111100
1100000000000011

func RotateLeft32 1.9

func RotateLeft32(x uint32, k int) uint32

RotateLeft32返回向左旋转(k mod 32)位的x的值. 要向右旋转k位,请调用RotateLeft32(x,-k).

该函数的执行时间不取决于输入.

Example

00000000000000000000000000001111
00000000000000000000000000111100
11000000000000000000000000000011

func RotateLeft64 1.9

func RotateLeft64(x uint64, k int) uint64

RotateLeft64返回向左旋转(k mod 64)位的x的值. 要向右旋转k位,请调用RotateLeft64(x,-k).

该函数的执行时间不取决于输入.

Example

0000000000000000000000000000000000000000000000000000000000001111
0000000000000000000000000000000000000000000000000000000000111100
1100000000000000000000000000000000000000000000000000000000000011

func RotateLeft8 1.9

func RotateLeft8(x uint8, k int) uint8

RotateLeft8返回向左旋转(k mod 8)位的x的值. 要向右旋转k位,请调用RotateLeft8(x,-k).

该函数的执行时间不取决于输入.

Example

00001111
00111100
11000011

func Sub 1.12

func Sub(x, y, borrow uint) (diff, borrowOut uint)

Sub返回x,y和借位之差:diff = x-y-借位. 借位输入必须为0或1; 否则,行为是不确定的. 借出输出保证为0或1.

该函数的执行时间不取决于输入.

func Sub32 1.12

func Sub32(x, y, borrow uint32) (diff, borrowOut uint32)

Sub32返回x,y和借位之差,diff = x-y-借位. 借位输入必须为0或1; 否则,行为是不确定的. 借出输出保证为0或1.

该函数的执行时间不取决于输入.

func Sub64 1.12

func Sub64(x, y, borrow uint64) (diff, borrowOut uint64)

Sub64返回x,y和借位之差:diff = x-y-借位. 借位输入必须为0或1; 否则,行为是不确定的. 借出输出保证为0或1.

该函数的执行时间不取决于输入.

func TrailingZeros 1.9

func TrailingZeros(x uint) int

TrailingZeros返回x中的尾随零位的数量; 结果是x == 0的UintSize.

func TrailingZeros16 1.9

func TrailingZeros16(x uint16) int

TrailingZeros16返回x中的尾随零位的数目; x == 0的结果是16.

Example

TrailingZeros16(0000000000001110) = 1

func TrailingZeros32 1.9

func TrailingZeros32(x uint32) int

TrailingZeros32返回x中尾随零位的数目; x == 0的结果是32.

Example

TrailingZeros32(00000000000000000000000000001110) = 1

func TrailingZeros64 1.9

func TrailingZeros64(x uint64) int

TrailingZeros64返回x中尾随零位的数量; x == 0的结果是64.

Example

TrailingZeros64(0000000000000000000000000000000000000000000000000000000000001110) = 1

func TrailingZeros8 1.9

func TrailingZeros8(x uint8) int

TrailingZeros8返回x中尾随零位的数量; 对于x == 0,结果为8.

Example

TrailingZeros8(00001110) = 1

by  ICOPY.SITE