bitutils

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Error           = errors.New("bitutils")
	ErrAlignment    = fmt.Errorf("%w:alignment", Error)
	ErrDivideByZero = fmt.Errorf("%w division by zero", Error)
)

Functions

func AlignUp

func AlignUp(n, align uint64) (uint64, error)

AlignUp rounds n up to the next multiple of align, where align is a power of 2.

func CeilDiv

func CeilDiv(a, b uint64) (uint64, error)

CeilDiv computes the ceiling of a/b without floating-point arithmetic.

func ClearLowestBit

func ClearLowestBit(n uint64) uint64

ClearLowestBit clears the least significant set bit in n and returns the result.

func FastMod

func FastMod(n, m uint64) (uint64, error)

FastMod computes n % m efficiently when m is a power of 2.

func FindLowestBit

func FindLowestBit(n uint64) uint64

FindLowestBit returns the index of the least significant set bit in n (0-based). Returns 0 if n is 0.

func Log2Ceil

func Log2Ceil(n uint64) uint64

Log2Ceil returns the ceiling of the base-2 logarithm of n. Returns 0 if n is 0.

func NextPowerOfTwo

func NextPowerOfTwo(n uint64) uint64

NextPowerOfTwo returns the next power of 2 >= n.

func ReverseBits

func ReverseBits(n uint64) uint64

ReverseBits reverses the bits of a 64-bit unsigned integer.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL