Binary and byte functions
Energy.Base.Binary class is the default collection of binary utility functions.
NOTE: The legacy
Energy.Base.Bit,Energy.Base.Byte, andEnergy.Base.Bcdclasses remain only for backward compatibility and are marked as obsolete. Always referenceEnergy.Base.Binary(orEnergy.Base.Binary.Bcd) directly when calling these helpers.
Compare
Compare byte arrays.
int Energy.Base.Binary.Compare(byte[] left, byte[] right)
Reverse
Reverse order of bytes.
Exchange lower byte with higher one
ushort Energy.Base.Binary.Reverse(ushort value)
uint Energy.Base.Binary.Reverse(uint value)
Endianess
Take up to two 16-bit unsigned words and return them as 32-bit unsigned word.
MSB / Big-Endian.
UInt32 Energy.Base.Binary.GetUInt32MSB(params UInt16[] array)
Take up to two 16-bit unsigned words and return them as 32-bit unsigned word.
LSB / Little-Endian.
UInt32 Energy.Base.Binary.GetUInt32LSB(params UInt16[] array)
NOT
Perform bitwise NOT operation on scalars or every byte in an array.
byte Energy.Base.Binary.Not(byte value)
uint Energy.Base.Binary.Not(uint value)
ulong Energy.Base.Binary.Not(ulong value)
byte[] Energy.Base.Binary.Not(byte[] array)
OR
Perform bitwise OR operation on scalars or every byte in an array.
When two byte arrays are provided, the shorter one is treated as a ring buffer.
byte Energy.Base.Binary.Or(byte one, byte two)
uint Energy.Base.Binary.Or(uint one, uint two)
ulong Energy.Base.Binary.Or(ulong one, ulong two)
byte[] Energy.Base.Binary.Or(byte[] one, byte[] two)
AND
Perform bitwise AND operation on scalars or every byte in an array.
When two byte arrays are provided, the shorter one is treated as a ring buffer.
byte Energy.Base.Binary.And(byte one, byte two)
uint Energy.Base.Binary.And(uint one, uint two)
ulong Energy.Base.Binary.And(ulong one, ulong two)
byte[] Energy.Base.Binary.And(byte[] one, byte[] two)
XOR
Perform bitwise XOR operation on scalars or every byte in an array.
When two byte arrays are provided, the shorter one is treated as a ring buffer.
byte Energy.Base.Binary.Xor(byte one, byte two)
uint Energy.Base.Binary.Xor(uint one, uint two)
ulong Energy.Base.Binary.Xor(ulong one, ulong two)
byte[] Energy.Base.Binary.Xor(byte[] one, byte[] two)
SHL
Shift bits left by a specified bit count. Negative counts automatically call the right-shift overloads.
Array overloads accept any positive count, including whole-byte shifts, and fill with zeros on the right.
byte Energy.Base.Binary.Shl(byte value, int count)
uint Energy.Base.Binary.Shl(uint value, int count)
ulong Energy.Base.Binary.Shl(ulong value, int count)
byte[] Energy.Base.Binary.Shl(byte[] array, int count)
SHR
Shift bits right by a specified bit count. Negative counts automatically call the left-shift overloads.
Array overloads accept any positive count, including whole-byte shifts, and fill with zeros on the left.
byte Energy.Base.Binary.Shr(byte value, int count)
uint Energy.Base.Binary.Shr(uint value, int count)
ulong Energy.Base.Binary.Shr(ulong value, int count)
byte[] Energy.Base.Binary.Shr(byte[] array, int count)
ROL
Rotate bits left in an array by given bit count.
When negative number of bits is given, right rotation will be performed instead.
byte[] Energy.Base.Binary.Rol(byte[] array, int count)
ROR
Rotate bits right in an array by given bit count.
When negative number of bits is given, left rotation will be performed instead.
byte[] Energy.Base.Binary.Ror(byte[] array, int count)
Bcd helpers
Binary-coded decimal helpers are exposed through the nested Energy.Base.Binary.Bcd class.
byte Energy.Base.Binary.Bcd.ToByte(byte value)
byte Energy.Base.Binary.Bcd.FromByte(byte value)
ushort Energy.Base.Binary.Bcd.ToWord(ushort value)
ushort Energy.Base.Binary.Bcd.FromWord(ushort value)