/go-byteutils

Utils for managing bits, bytes, and converting to an from them

Primary LanguageGoMIT LicenseMIT

byteutils

CI codecov Go Report Card Go Reference

Utilities for managing bytes, such as indexing into a byte to get an individual bit and converting types like uint to and from []byte.

Example

fmt.Println(byteutils.ToUint16([]byte{0x01, 0x00}, byteutils.LittleEndian)) // 256

b := 0b0001_0000
fmt.Println(byteutils.GetL(b, 3)) // 1 (index from left)
byteutils.SetL(&b, 4) // set index 4 from left to 1
fmt.Println(byteutils.GetR(b, 3)) // 1 (index from right)

fmt.Printf("%b\n", byteutils.SliceL(0b00110000, 2, 4)) // 11