bits

package module
v0.0.0-...-6ea1a2a Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: MIT Imports: 6 Imported by: 0

README

go-bitnuts

GoDoc Coverage Status Go Report Card

Bit twiddling, swapping, and maneuvering for go

Includes many functions useful if one is operating on a bit matrix. Some functions include shifting bits in an array to the left or right, shifting bits in a matrix up or down, etc.

Warning

This library was yanked out of a test program and needs some TLC if it is to be used in production. Particularly, many of the operations are not optimized in the least, and were created simply to get the job done.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(from byte, start, finish uint8) byte

Copy creates a new byte with the bits from start to finish copied and the rest of the bits as zeros

func CopyMatrix

func CopyMatrix(in [][]byte) [][]byte

CopyMatrix creates a replica byte matrix

func CopyPaste

func CopyPaste(from, to, mask byte) byte

CopyPaste takes bit 'from' and copies all bits where 1's are found in the mask onto byte 'to'.

func CopyPasteRow

func CopyPasteRow(fromRow, toRow []byte, fromStartIdx, toStartIdx, width int) []byte

CopyPasteRow takes all the bits of a defined section in a byte slice and pastes them onto an equal length section of another byte slice

func CreateByteFromString

func CreateByteFromString(bt string) byte

CreateByteFromString takes a string of 1's and 0's and creates a byte. Must not be more than 8 characters

func CreateBytesFromString

func CreateBytesFromString(bts string) []byte

CreateBytesFromString takes a string of 1's and 0's and creates a slice of bytes.

func Float64ToBytes

func Float64ToBytes(num float64) []byte

Float64ToBytes converts a float64 into it's constituent bytes in big endian format

func Graph

func Graph(matrix [][]byte, fx grapher) [][]byte

Graph takes f(x) and toggles the matching bits in a byte matrix

func IsSet

func IsSet(bt byte, i uint8) bool

IsSet checks if the bit at i is set

func IsSetInRow

func IsSetInRow(row []byte, i int) bool

IsSetInRow checks if the bit at i in a slice of bits is set

func NewCopyPasteMask

func NewCopyPasteMask(start, stop uint8) byte

NewCopyPasteMask creates a bit mask in which the selected range is composed of 1's and the rest is composed of zeros. Both indexes are included.

func NewSimpleCopyPasteMask

func NewSimpleCopyPasteMask(index uint8) byte

NewSimpleCopyPasteMask creates a bit mask in which one selected bit at 'index' is a 1 and the rest of the byte is composed of zeros.

func PasteRight

func PasteRight(from, to byte, start uint8) byte

PasteRight pastes a result of Copy (or any byte section in which the rest of the byte contains only zeros) to the right side of byte 'to', starting at index 'start'

func PrintMatrix

func PrintMatrix(matrix [][]byte)

PrintMatrix prints a matrix of bytes in an easy to view checkerboard format

func Set

func Set(bt byte, i uint8) byte

Set makes the bit at i in a byte 1

func SetInRow

func SetInRow(row []byte, i int) []byte

SetInRow makes the bit at i in a slice of bits 1

func ShiftDown

func ShiftDown(matrix [][]byte, index float64, count float64) [][]byte

ShiftDown takes a matrix of bytes and shifts a column of bits down by 'count'. Bits pushed off the bottom are rotated back around to the top. Each slice in the matrix is expected to be the same length.

func ShiftLeft

func ShiftLeft(bytes []byte, count float64) []byte

ShiftLeft takes an array of bytes lined up horizontally, bit to bit, and shifts the whole array left by 'count'. Bits pushed off the left edge are rotated to the right side.

func ShiftRight

func ShiftRight(bytes []byte, count float64) []byte

ShiftRight takes an array of bytes lined up horizontally, bit to bit, and shifts the whole array right by 'count'. Bits pushed off the right edge are rotated to the left side.

func ShiftUp

func ShiftUp(matrix [][]byte, index float64, count float64) [][]byte

ShiftUp takes a matrix of bytes and shifts a column of bits up by 'count'. Bits pushed off the top are rotated back around to the bottom. Each slice in the matrix is expected to be the same length.

func SinWave

func SinWave(matrix [][]byte, yStart, widthCoef float64) [][]byte

SinWave toggles a variable width sine wave on a byte matrix

func SinWaveFunky

func SinWaveFunky(matrix [][]byte, yStart, cosCoef, sinCoef float64) [][]byte

SinWaveFunky toggles a variable width sine wave on a byte matrix

func SpiralBottomLeft

func SpiralBottomLeft(matrix [][]byte) [][]byte

SpiralBottomLeft toggles bits of a byte matrix in a spiral starting at the bottom left and going clockwise

func SpiralBottomRight

func SpiralBottomRight(matrix [][]byte) [][]byte

SpiralBottomRight toggles bits of a byte matrix in a spiral starting at the bottom right and going clockwise

func SpiralTopLeft

func SpiralTopLeft(matrix [][]byte) [][]byte

SpiralTopLeft toggles bits of a byte matrix in a spiral starting at the top left and going clockwise

func SpiralTopRight

func SpiralTopRight(matrix [][]byte) [][]byte

SpiralTopRight toggles bits of a byte matrix in a spiral starting at the top right and going clockwise

func SprintBytes

func SprintBytes(bts []byte) string

SprintBytes returns the string representation of a byte slice

func SwapHorizontal

func SwapHorizontal(matrix [][]byte, xStart, yStart, singleSectionWidth, height int) [][]byte

SwapHorizontal takes a matrix of bytes and swaps a section from left to right.

func SwapVertical

func SwapVertical(matrix [][]byte, xStart, yStart, width, singleSectionHeight int) [][]byte

SwapVertical takes a matrix of bytes and swaps a section from bottom to top.

func Toggle

func Toggle(bt byte, index uint8) byte

Toggle the bit at index in a byte

func ToggleColumn

func ToggleColumn(matrix [][]byte, index float64) [][]byte

ToggleColumn toggles all the bits in the selected column of a byte matrix

func ToggleColumnSection

func ToggleColumnSection(matrix [][]byte, col float64, start, end int) [][]byte

ToggleColumnSection toggles all the bits in the selected column of a byte matrix from start to end

func ToggleColumns

func ToggleColumns(data [][]byte, start, end int) [][]byte

ToggleColumns toggles all the bits in the columns of the byte matrix selected by start and end

func ToggleColumnsSections

func ToggleColumnsSections(matrix [][]byte, start, end float64, yStart, yEnd int) [][]byte

ToggleColumnsSections toggles all the bits in the byte array columns selected by start and end for a specific section

func ToggleRow

func ToggleRow(data []byte) []byte

ToggleRow toggles all of the bits in a byte array

func ToggleRowSection

func ToggleRowSection(data []byte, start, end int) []byte

ToggleRowSection toggles all of the bits from start to end bit index in a byte array

func ToggleRows

func ToggleRows(data [][]byte, start, end int) [][]byte

ToggleRows toggles all the bits in the byte array rows selected by start and end

func ToggleRowsSections

func ToggleRowsSections(data [][]byte, start, end, xStart, xEnd int) [][]byte

ToggleRowsSections toggles all the bits in the byte array rows selected by start and end for a specific section

func ToggleUsingFloat64

func ToggleUsingFloat64(matrix [][]byte, f float64) [][]byte

ToggleUsingFloat64 takes the bytes in a given float and uses them as masks to toggle values across a matrix

func ToggleUsingUint64

func ToggleUsingUint64(matrix [][]byte, u uint64) [][]byte

ToggleUsingUint64 takes the bytes in a given uint and uses them as masks to toggle values across a matrix

func Uint64ToBytes

func Uint64ToBytes(num uint64) []byte

Uint64ToBytes converts a uint64 into it's constituent bytes in big endian format

func Unset

func Unset(bt byte, i uint8) byte

Unset makes the bit at i in a byte 0

func UnsetInRow

func UnsetInRow(row []byte, i int) []byte

UnsetInRow makes the bit at i in a slice of bits 0

Types

This section is empty.

Jump to

Keyboard shortcuts

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