bitops

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package bitops provides various utility functions and types for low level bit-twiddling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLZ

func CLZ(x uint64) (n uint)

CLZ (Count Leading Zeros) counts the number of leading zeroes before the most significant bit in x that is set to 1. Calling CLZ(0) is undefined behavior.

func FFS

func FFS(x uint64) (n uint)

FFS (Find First Set) returns the index of the least significant bit in x that is set to 1. Calling FFS(0) is undefined behavior.

func GetLE16

func GetLE16(b []byte) uint16

GetLE16 gets a 16 bit little endian number from memory.

func GetLE32

func GetLE32(b []byte) uint32

GetLE32 gets a 32 bit little endian number from memory.

func PutLE16

func PutLE16(b []byte, v uint16)

PutLE16 puts a 16 bit little endian number into memory.

func PutLE32

func PutLE32(b []byte, v uint32)

PutLE32 puts a 32 bit little endian number into memory.

func TwoBitArrayLength

func TwoBitArrayLength(count int) int

TwoBitArrayLength returns the length necessary for a byte slice to hold a TwoBitArray with count elements.

Types

type TwoBitArray

type TwoBitArray []byte

TwoBitArray is a bit array with two bits per entry. Within each byte in the TwoBitArray, position 0 points to the least significant 2 bits while position 3 points to the most significant 2 bits.

func (TwoBitArray) Get

func (tba TwoBitArray) Get(pos uint) byte

Get returns the value of the 2 bits at the position pos in the lowest 2 bits of returned byte.

func (TwoBitArray) Set

func (tba TwoBitArray) Set(pos uint, val byte)

Set sets the value of the 2 bits at position pos to the value of the lowest 2 bits in val.

Jump to

Keyboard shortcuts

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