Hexadecimal
Functions that support hexadecimal numeral system conversions.
ArrayToHex
Convert byte array to hexadecimal string.
string Energy.Base.Hex.ArrayToHex(byte[] array)
string Energy.Base.Hex.ArrayToHex(byte[] array, string space)
HexToArray
Convert hexadecimal string to byte array.
This is strict version of conversion function.
Hexadecimal string should contain only digits and small or upper letters A-F. Any other character is treated as zero.
byte[] Energy.Base.Hex.HexToArray(string hex)
This version of conversion function allows to use whitespace characters.
byte[] Energy.Base.Hex.HexToArray(string hex, bool ignoreWhite)
This version of conversion function allows to use prefixes (like “0x” or “$”) and whitespace characters.
byte[] Energy.Base.Hex.HexToArray(string hex, bool ignoreWhite, string[] prefix)
var b = Energy.Base.Hex.HexToArray("0x 12 33", true, new string[] { "0x" });
BinToHex
Convert binary string to hexadecimal string.
string Energy.Base.Hex.BinToHex(string bin)
HexToBin
Convert hexadecimal string to binary string.
Note that hexadecimal “0” will be represented with leading zeroes as “0000” in binary. Resulting binary string will always have a length divisible by 4.
Works also when hexadecimal string starts with “0x” or “$”.
string Energy.Base.Hex.HexToBin(string hex)
HexToByte
Convert hexadecimal string to byte value (System.Byte).
byte Energy.Base.Hex.HexToByte(string hex)
RemovePrefix
Remove leading prefix “0x”, “0X” or “$” from hexadecimal string.
string Energy.Base.Hex.RemovePrefix(string hex)
ByteToPrintable
Convert byte to printable character.
All non-ASCII characters will be represented as dot character. Bytes 0, 128 and 255 will be represented as space.
char Energy.Base.Hex.ByteToPrintable(byte b)
ByteToHex
Convert a single byte to a two-character hexadecimal string.
string Energy.Base.Hex.ByteToHex(byte value)
IntegerToHex
Convert an integer to a hexadecimal string, optionally padded to a byte size and capitalized.
string Energy.Base.Hex.IntegerToHex(int value)
string Energy.Base.Hex.IntegerToHex(int value, bool uppperCase)
string Energy.Base.Hex.IntegerToHex(int value, int size)
string Energy.Base.Hex.IntegerToHex(int value, int size, bool capitalize)
HexToInteger
Convert a hexadecimal string to an integer. Companion overloads return wider types.
int Energy.Base.Hex.HexToInteger(string hex)
short Energy.Base.Hex.HexToShort(string hex)
long Energy.Base.Hex.HexToLong(string hex)
StringToHex
Convert text to its hexadecimal representation using the given encoding.
string Energy.Base.Hex.StringToHex(string text)
string Energy.Base.Hex.StringToHex(string text, string encoding)
string Energy.Base.Hex.StringToHex(string text, System.Text.Encoding encoding)
HexToString
Convert a hexadecimal string back to text using the given encoding.
string Energy.Base.Hex.HexToString(string hex)
string Energy.Base.Hex.HexToString(string hex, string encoding)
string Energy.Base.Hex.HexToString(string hex, System.Text.Encoding encoding)
IsHex
Check whether a string is a valid hexadecimal value. Overloads accept allowed prefixes and whether to ignore whitespace.
bool Energy.Base.Hex.IsHex(string value)
bool Energy.Base.Hex.IsHex(string value, string[] prefixArray)
bool Energy.Base.Hex.IsHex(string value, string[] prefixArray, bool ignoreWhite)
Print
Format a byte array as a human-readable hex dump with configurable line size, grouping, offset column, word size, and ASCII representation.
string Energy.Base.Hex.Print(byte[] array)
string Energy.Base.Hex.Print(byte[] array, int lineSize)
string Energy.Base.Hex.Print(byte[] array, int lineSize, int groupSize)
string Energy.Base.Hex.Print(byte[] array, int lineSize, int groupSize, bool representation)