twoscomplement

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: GPL-3.0 Imports: 2 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyAlignRight

func CopyAlignRight(input []byte, targetLength int) []byte

CopyAlignRight yields a copy of the bytes, of specific length. If output is longer than input, it will pad left with zeroes. If output if shorter than input, input will be trimmed to the left. The right-most bytes always remain in place.

func FromBytes

func FromBytes(twosBytes []byte) *big.Int

FromBytes converts a byte array to a number. Interprets input as a 2's complement representation if the first bit (most significant) is 1. Big endian.

func SetBytes

func SetBytes(z *big.Int, twosBytes []byte) *big.Int

SetBytes changes z to be the number represented as bytes in 2's complement, and returns z. Big endian.

func ToBytes

func ToBytes(bi *big.Int) []byte

ToBytes returns a byte array of variable length representing the input big.Int in two's complement. Does not alter input.

func ToBytesOfLength

func ToBytesOfLength(i *big.Int, bytesLength int) ([]byte, error)

ToBytesOfLength returns a byte array representation, 2's complement if number is negative. Big endian. Will return error if value does not fit in requested number of bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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