bits

package
v0.0.0-...-5d27878 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 0 Imported by: 1

Documentation

Overview

Package bits provides utils for manipulation bits of a single byte

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstructByteOfQuarters

func ConstructByteOfQuarters(first, second, third, fourth byte) byte

ConstructByteOfQuarters constructs a byte of it's four quarters given

Example
fmt.Printf("%08b", ConstructByteOfQuarters(3, 2, 1, 3)) // 00000011 00000010 00000001 00000011 in binary
Output:

11100111

func ConstructByteOfQuartersAsSlice

func ConstructByteOfQuartersAsSlice(b []byte) byte

ConstructByteOfQuartersAsSlice constructs a byte of it's four quarters given as byte slice

Example
var quarters = []byte{3, 2, 1, 3} // 00000011 00000010 00000001 00000011 in binary
fmt.Printf("%08b", ConstructByteOfQuartersAsSlice(quarters))
Output:

11100111

func GetLastTwoBits

func GetLastTwoBits(b byte) byte

GetLastTwoBits returns byte containing only last two bits of given byte

Example
fmt.Printf("%08b", GetLastTwoBits(134)) // 134 is 10000110 in binary
Output:

00000010

func QuartersOfByte

func QuartersOfByte(b byte) [4]byte

QuartersOfByte returns a byte's four quarters of bits

Example
fmt.Printf("%08b", QuartersOfByte(231)) //231 is 11100111 in binary
Output:

[00000011 00000010 00000001 00000011]

func SetLastTwoBits

func SetLastTwoBits(b byte, value byte) byte

SetLastTwoBits modifies last two bits of given byte

Example
fmt.Printf("%08b", SetLastTwoBits(134, 1)) // 134 is 10000110 and 1 is 00000001 in binary
Output:

10000101

Types

This section is empty.

Jump to

Keyboard shortcuts

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