Movatterモバイル変換


[0]ホーム

URL:


bits

packagestandard library
go1.25.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:1Imported by:47,031

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

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

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

Index

Examples

Constants

View Source
const UintSize = uintSize

UintSize is the size of a uint in bits.

Variables

This section is empty.

Functions

funcAddadded ingo1.12

func Add(x, y, carryuint) (sum, carryOutuint)

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.

funcAdd32added ingo1.12

func Add32(x, y, carryuint32) (sum, carryOutuint32)

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.

Example
package mainimport ("fmt""math/bits")func main() {// First number is 33<<32 + 12n1 := []uint32{33, 12}// Second number is 21<<32 + 23n2 := []uint32{21, 23}// Add them together without producing carry.d1, carry := bits.Add32(n1[1], n2[1], 0)d0, _ := bits.Add32(n1[0], n2[0], carry)nsum := []uint32{d0, d1}fmt.Printf("%v + %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)// First number is 1<<32 + 2147483648n1 = []uint32{1, 0x80000000}// Second number is 1<<32 + 2147483648n2 = []uint32{1, 0x80000000}// Add them together producing carry.d1, carry = bits.Add32(n1[1], n2[1], 0)d0, _ = bits.Add32(n1[0], n2[0], carry)nsum = []uint32{d0, d1}fmt.Printf("%v + %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)}
Output:[33 12] + [21 23] = [54 35] (carry bit was 0)[1 2147483648] + [1 2147483648] = [3 0] (carry bit was 1)

funcAdd64added ingo1.12

func Add64(x, y, carryuint64) (sum, carryOutuint64)

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.

Example
package mainimport ("fmt""math/bits")func main() {// First number is 33<<64 + 12n1 := []uint64{33, 12}// Second number is 21<<64 + 23n2 := []uint64{21, 23}// Add them together without producing carry.d1, carry := bits.Add64(n1[1], n2[1], 0)d0, _ := bits.Add64(n1[0], n2[0], carry)nsum := []uint64{d0, d1}fmt.Printf("%v + %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)// First number is 1<<64 + 9223372036854775808n1 = []uint64{1, 0x8000000000000000}// Second number is 1<<64 + 9223372036854775808n2 = []uint64{1, 0x8000000000000000}// Add them together producing carry.d1, carry = bits.Add64(n1[1], n2[1], 0)d0, _ = bits.Add64(n1[0], n2[0], carry)nsum = []uint64{d0, d1}fmt.Printf("%v + %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)}
Output:[33 12] + [21 23] = [54 35] (carry bit was 0)[1 9223372036854775808] + [1 9223372036854775808] = [3 0] (carry bit was 1)

funcDivadded ingo1.12

func Div(hi, lo, yuint) (quo, remuint)

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

funcDiv32added ingo1.12

func Div32(hi, lo, yuint32) (quo, remuint32)

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

Example
package mainimport ("fmt""math/bits")func main() {// First number is 0<<32 + 6n1 := []uint32{0, 6}// Second number is 0<<32 + 3n2 := []uint32{0, 3}// Divide them together.quo, rem := bits.Div32(n1[0], n1[1], n2[1])nsum := []uint32{quo, rem}fmt.Printf("[%v %v] / %v = %v\n", n1[0], n1[1], n2[1], nsum)// First number is 2<<32 + 2147483648n1 = []uint32{2, 0x80000000}// Second number is 0<<32 + 2147483648n2 = []uint32{0, 0x80000000}// Divide them together.quo, rem = bits.Div32(n1[0], n1[1], n2[1])nsum = []uint32{quo, rem}fmt.Printf("[%v %v] / %v = %v\n", n1[0], n1[1], n2[1], nsum)}
Output:[0 6] / 3 = [2 0][2 2147483648] / 2147483648 = [5 0]

funcDiv64added ingo1.12

func Div64(hi, lo, yuint64) (quo, remuint64)

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

Example
package mainimport ("fmt""math/bits")func main() {// First number is 0<<64 + 6n1 := []uint64{0, 6}// Second number is 0<<64 + 3n2 := []uint64{0, 3}// Divide them together.quo, rem := bits.Div64(n1[0], n1[1], n2[1])nsum := []uint64{quo, rem}fmt.Printf("[%v %v] / %v = %v\n", n1[0], n1[1], n2[1], nsum)// First number is 2<<64 + 9223372036854775808n1 = []uint64{2, 0x8000000000000000}// Second number is 0<<64 + 9223372036854775808n2 = []uint64{0, 0x8000000000000000}// Divide them together.quo, rem = bits.Div64(n1[0], n1[1], n2[1])nsum = []uint64{quo, rem}fmt.Printf("[%v %v] / %v = %v\n", n1[0], n1[1], n2[1], nsum)}
Output:[0 6] / 3 = [2 0][2 9223372036854775808] / 9223372036854775808 = [5 0]

funcLeadingZeros

func LeadingZeros(xuint)int

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

funcLeadingZeros16

func LeadingZeros16(xuint16)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("LeadingZeros16(%016b) = %d\n", 1, bits.LeadingZeros16(1))}
Output:LeadingZeros16(0000000000000001) = 15

funcLeadingZeros32

func LeadingZeros32(xuint32)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("LeadingZeros32(%032b) = %d\n", 1, bits.LeadingZeros32(1))}
Output:LeadingZeros32(00000000000000000000000000000001) = 31

funcLeadingZeros64

func LeadingZeros64(xuint64)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("LeadingZeros64(%064b) = %d\n", 1, bits.LeadingZeros64(1))}
Output:LeadingZeros64(0000000000000000000000000000000000000000000000000000000000000001) = 63

funcLeadingZeros8

func LeadingZeros8(xuint8)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("LeadingZeros8(%08b) = %d\n", 1, bits.LeadingZeros8(1))}
Output:LeadingZeros8(00000001) = 7

funcLen

func Len(xuint)int

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

funcLen16

func Len16(xuint16) (nint)

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8))}
Output:Len16(0000000000001000) = 4

funcLen32

func Len32(xuint32) (nint)

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8))}
Output:Len32(00000000000000000000000000001000) = 4

funcLen64

func Len64(xuint64) (nint)

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8))}
Output:Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4

funcLen8

func Len8(xuint8)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8))}
Output:Len8(00001000) = 4

funcMuladded ingo1.12

func Mul(x, yuint) (hi, louint)

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

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

funcMul32added ingo1.12

func Mul32(x, yuint32) (hi, louint32)

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

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

Example
package mainimport ("fmt""math/bits")func main() {// First number is 0<<32 + 12n1 := []uint32{0, 12}// Second number is 0<<32 + 12n2 := []uint32{0, 12}// Multiply them together without producing overflow.hi, lo := bits.Mul32(n1[1], n2[1])nsum := []uint32{hi, lo}fmt.Printf("%v * %v = %v\n", n1[1], n2[1], nsum)// First number is 0<<32 + 2147483648n1 = []uint32{0, 0x80000000}// Second number is 0<<32 + 2n2 = []uint32{0, 2}// Multiply them together producing overflow.hi, lo = bits.Mul32(n1[1], n2[1])nsum = []uint32{hi, lo}fmt.Printf("%v * %v = %v\n", n1[1], n2[1], nsum)}
Output:12 * 12 = [0 144]2147483648 * 2 = [1 0]

funcMul64added ingo1.12

func Mul64(x, yuint64) (hi, louint64)

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

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

Example
package mainimport ("fmt""math/bits")func main() {// First number is 0<<64 + 12n1 := []uint64{0, 12}// Second number is 0<<64 + 12n2 := []uint64{0, 12}// Multiply them together without producing overflow.hi, lo := bits.Mul64(n1[1], n2[1])nsum := []uint64{hi, lo}fmt.Printf("%v * %v = %v\n", n1[1], n2[1], nsum)// First number is 0<<64 + 9223372036854775808n1 = []uint64{0, 0x8000000000000000}// Second number is 0<<64 + 2n2 = []uint64{0, 2}// Multiply them together producing overflow.hi, lo = bits.Mul64(n1[1], n2[1])nsum = []uint64{hi, lo}fmt.Printf("%v * %v = %v\n", n1[1], n2[1], nsum)}
Output:12 * 12 = [0 144]9223372036854775808 * 2 = [1 0]

funcOnesCount

func OnesCount(xuint)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("OnesCount(%b) = %d\n", 14, bits.OnesCount(14))}
Output:OnesCount(1110) = 3

funcOnesCount16

func OnesCount16(xuint16)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("OnesCount16(%016b) = %d\n", 14, bits.OnesCount16(14))}
Output:OnesCount16(0000000000001110) = 3

funcOnesCount32

func OnesCount32(xuint32)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("OnesCount32(%032b) = %d\n", 14, bits.OnesCount32(14))}
Output:OnesCount32(00000000000000000000000000001110) = 3

funcOnesCount64

func OnesCount64(xuint64)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("OnesCount64(%064b) = %d\n", 14, bits.OnesCount64(14))}
Output:OnesCount64(0000000000000000000000000000000000000000000000000000000000001110) = 3

funcOnesCount8

func OnesCount8(xuint8)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("OnesCount8(%08b) = %d\n", 14, bits.OnesCount8(14))}
Output:OnesCount8(00001110) = 3

funcRemadded ingo1.14

func Rem(hi, lo, yuint)uint

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

funcRem32added ingo1.14

func Rem32(hi, lo, yuint32)uint32

Rem32 returns the remainder of (hi, lo) divided by y. Rem32 panicsfor y == 0 (division by zero) but, unlikeDiv32, it doesn't panicon a quotient overflow.

funcRem64added ingo1.14

func Rem64(hi, lo, yuint64)uint64

Rem64 returns the remainder of (hi, lo) divided by y. Rem64 panicsfor y == 0 (division by zero) but, unlikeDiv64, it doesn't panicon a quotient overflow.

funcReverse

func Reverse(xuint)uint

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

funcReverse16

func Reverse16(xuint16)uint16

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%016b\n", 19)fmt.Printf("%016b\n", bits.Reverse16(19))}
Output:00000000000100111100100000000000

funcReverse32

func Reverse32(xuint32)uint32

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%032b\n", 19)fmt.Printf("%032b\n", bits.Reverse32(19))}
Output:0000000000000000000000000001001111001000000000000000000000000000

funcReverse64

func Reverse64(xuint64)uint64

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%064b\n", 19)fmt.Printf("%064b\n", bits.Reverse64(19))}
Output:00000000000000000000000000000000000000000000000000000000000100111100100000000000000000000000000000000000000000000000000000000000

funcReverse8

func Reverse8(xuint8)uint8

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%08b\n", 19)fmt.Printf("%08b\n", bits.Reverse8(19))}
Output:0001001111001000

funcReverseBytes

func ReverseBytes(xuint)uint

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

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

funcReverseBytes16

func ReverseBytes16(xuint16)uint16

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

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%016b\n", 15)fmt.Printf("%016b\n", bits.ReverseBytes16(15))}
Output:00000000000011110000111100000000

funcReverseBytes32

func ReverseBytes32(xuint32)uint32

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

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%032b\n", 15)fmt.Printf("%032b\n", bits.ReverseBytes32(15))}
Output:0000000000000000000000000000111100001111000000000000000000000000

funcReverseBytes64

func ReverseBytes64(xuint64)uint64

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

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%064b\n", 15)fmt.Printf("%064b\n", bits.ReverseBytes64(15))}
Output:00000000000000000000000000000000000000000000000000000000000011110000111100000000000000000000000000000000000000000000000000000000

funcRotateLeft

func RotateLeft(xuint, kint)uint

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

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

funcRotateLeft16

func RotateLeft16(xuint16, kint)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).

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%016b\n", 15)fmt.Printf("%016b\n", bits.RotateLeft16(15, 2))fmt.Printf("%016b\n", bits.RotateLeft16(15, -2))}
Output:000000000000111100000000001111001100000000000011

funcRotateLeft32

func RotateLeft32(xuint32, kint)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).

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%032b\n", 15)fmt.Printf("%032b\n", bits.RotateLeft32(15, 2))fmt.Printf("%032b\n", bits.RotateLeft32(15, -2))}
Output:000000000000000000000000000011110000000000000000000000000011110011000000000000000000000000000011

funcRotateLeft64

func RotateLeft64(xuint64, kint)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).

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%064b\n", 15)fmt.Printf("%064b\n", bits.RotateLeft64(15, 2))fmt.Printf("%064b\n", bits.RotateLeft64(15, -2))}
Output:000000000000000000000000000000000000000000000000000000000000111100000000000000000000000000000000000000000000000000000000001111001100000000000000000000000000000000000000000000000000000000000011

funcRotateLeft8

func RotateLeft8(xuint8, kint)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).

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("%08b\n", 15)fmt.Printf("%08b\n", bits.RotateLeft8(15, 2))fmt.Printf("%08b\n", bits.RotateLeft8(15, -2))}
Output:000011110011110011000011

funcSubadded ingo1.12

func Sub(x, y, borrowuint) (diff, borrowOutuint)

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.

funcSub32added ingo1.12

func Sub32(x, y, borrowuint32) (diff, borrowOutuint32)

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.

Example
package mainimport ("fmt""math/bits")func main() {// First number is 33<<32 + 23n1 := []uint32{33, 23}// Second number is 21<<32 + 12n2 := []uint32{21, 12}// Sub them together without producing carry.d1, carry := bits.Sub32(n1[1], n2[1], 0)d0, _ := bits.Sub32(n1[0], n2[0], carry)nsum := []uint32{d0, d1}fmt.Printf("%v - %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)// First number is 3<<32 + 2147483647n1 = []uint32{3, 0x7fffffff}// Second number is 1<<32 + 2147483648n2 = []uint32{1, 0x80000000}// Sub them together producing carry.d1, carry = bits.Sub32(n1[1], n2[1], 0)d0, _ = bits.Sub32(n1[0], n2[0], carry)nsum = []uint32{d0, d1}fmt.Printf("%v - %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)}
Output:[33 23] - [21 12] = [12 11] (carry bit was 0)[3 2147483647] - [1 2147483648] = [1 4294967295] (carry bit was 1)

funcSub64added ingo1.12

func Sub64(x, y, borrowuint64) (diff, borrowOutuint64)

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.

Example
package mainimport ("fmt""math/bits")func main() {// First number is 33<<64 + 23n1 := []uint64{33, 23}// Second number is 21<<64 + 12n2 := []uint64{21, 12}// Sub them together without producing carry.d1, carry := bits.Sub64(n1[1], n2[1], 0)d0, _ := bits.Sub64(n1[0], n2[0], carry)nsum := []uint64{d0, d1}fmt.Printf("%v - %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)// First number is 3<<64 + 9223372036854775807n1 = []uint64{3, 0x7fffffffffffffff}// Second number is 1<<64 + 9223372036854775808n2 = []uint64{1, 0x8000000000000000}// Sub them together producing carry.d1, carry = bits.Sub64(n1[1], n2[1], 0)d0, _ = bits.Sub64(n1[0], n2[0], carry)nsum = []uint64{d0, d1}fmt.Printf("%v - %v = %v (carry bit was %v)\n", n1, n2, nsum, carry)}
Output:[33 23] - [21 12] = [12 11] (carry bit was 0)[3 9223372036854775807] - [1 9223372036854775808] = [1 18446744073709551615] (carry bit was 1)

funcTrailingZeros

func TrailingZeros(xuint)int

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

funcTrailingZeros16

func TrailingZeros16(xuint16)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("TrailingZeros16(%016b) = %d\n", 14, bits.TrailingZeros16(14))}
Output:TrailingZeros16(0000000000001110) = 1

funcTrailingZeros32

func TrailingZeros32(xuint32)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("TrailingZeros32(%032b) = %d\n", 14, bits.TrailingZeros32(14))}
Output:TrailingZeros32(00000000000000000000000000001110) = 1

funcTrailingZeros64

func TrailingZeros64(xuint64)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("TrailingZeros64(%064b) = %d\n", 14, bits.TrailingZeros64(14))}
Output:TrailingZeros64(0000000000000000000000000000000000000000000000000000000000001110) = 1

funcTrailingZeros8

func TrailingZeros8(xuint8)int

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

Example
package mainimport ("fmt""math/bits")func main() {fmt.Printf("TrailingZeros8(%08b) = %d\n", 14, bits.TrailingZeros8(14))}
Output:TrailingZeros8(00001110) = 1

Types

This section is empty.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp