hexutil

package
v0.0.0-...-f5f0bdb Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Prefix hex prefix
	Prefix = "0x"

	// ErrInvalidHex is error for invalid hex
	ErrInvalidHex = errors.New("invalid hex")
)

Functions

func AddPrefix

func AddPrefix(hexStr string) string

AddPrefix adds the `0x` prefix to string values. Returns a `0x` prefixed string from the input value. If the input is already prefixed, it is returned unchanged. Adds extra 0 when `length % 2 == 1`.

func HasPrefix

func HasPrefix(hexStr string) bool

HasPrefix tests for the existence of a `0x` prefix. Checks for a valid hex input value and if the start matched `0x`.

func HexFixLength

func HexFixLength(hexStr string, bitLength int, withPadding bool) string

HexFixLength shifts a hex string to a specific bitLength. Returns a `0x` prefixed string with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Values with more bits are trimmed to the specified length. Input values with less bits are returned as-is by default. When `withPadding` is set, shorter values are padded with `0`.

func Reverse

func Reverse(s string) string

Reverse reverses a hex string

func StripPrefix

func StripPrefix(hexStr string) string

StripPrefix strips any leading `0x` prefix. Tests for the existence of a `0x` prefix, and returns the value without the prefix. Un-prefixed values are returned as-is.

func ToBN

func ToBN(hexStr string, isLittleEndian bool, isNegative bool) (*big.Int, error)

ToBN creates a math/big big number from a hex string.

func ToUint8Slice

func ToUint8Slice(hexStr string, bitLength int) ([]uint8, error)

ToUint8Slice creates a uint8 array from a hex string. empty inputs returns an empty array result. Hex input values return the actual bytes value converted to a uint8. Anything that is not a hex string (including the `0x` prefix) returns an error.

func ValidHex

func ValidHex(hexStr string) bool

ValidHex tests that the value is a valid string. The `0x` prefix is optional in the test. Empty string returns false.

Types

This section is empty.

Jump to

Keyboard shortcuts

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