bits

package
v0.0.0-...-720af6a Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesInBinary

func BytesInBinary(bs []byte) string

func ClearBit

func ClearBit[U constraints.Unsigned](store U, pos uint8) U

ClearBit clears the bit at pos in store.

func ClearBits

func ClearBits[U constraints.Unsigned](store U, from, to uint8) U

ClearBits clears all bits from "from" until "to".

func ClearBytes

func ClearBytes(b []byte, from, to uint8)

ClearBytes clears all the bytes at position from to position to.

func GetBit

func GetBit[U constraints.Unsigned](store U, pos uint8) bool

GetBit gets a single bit value from "store" in position "pos". true if set, false if not.

func GetValue

func GetValue[U, U1 constraints.Unsigned](store U, bitMask U, start uint64) U1

GetValue retrieves a value we stored with setValue. store is the unsigned number we stored the value in. bitMask is the mask to apply to retrieve the value. start tells us the starting position we stored in (we need to shift the number this many bits). So if you did something like: storage := setValue(uint8(0), uint64(0), 17, 24) You would retrieve with: getValue(storage, aMask, 17) Where "mask" would be generated with aMask := mask(uint32(17), uint32(24))

func Mask

func Mask[U constraints.Unsigned](start, end uint64) U

Mask creates a mask for setting, getting and clearing a set of bits. start is the bit location you wish to start at and end is the bit you wish to end at (exclusive). Index starts at 0. So mask(1, 4) will create a mask that includes bits at location 1 to 3. If start >= end, this will panic.

func SetBit

func SetBit[U constraints.Unsigned](store U, pos uint8, val bool) U

SetBit sets a single bit in "store" at position "pos" to value "val". If val is true, the bit is set to 1, if false, it is set to 0.

func SetValue

func SetValue[I, U constraints.Unsigned](val I, store U, start, end uint64) U

SetValue stores "val" in unsigned number "store" starting at bit "start" and ending at bit "end" (exclusive). If start >= end, this panics.

Types

type PtrUnsigned

type PtrUnsigned interface {
	*uint8 | *uint16 | *uint32 | *uint64
}

Jump to

Keyboard shortcuts

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