public static Nibble[] FromBytes(params byte[] bytes) { Nibble[] nibbles = new Nibble[2 * bytes.Length]; for (int i = 0; i < bytes.Length; i++) { nibbles[i * 2] = new Nibble((byte)((bytes[i] & 240) >> 4)); nibbles[i * 2 + 1] = new Nibble((byte)(bytes[i] & 15)); } return(nibbles); }
public static Nibble[] FromHexString(string hexString) { if (hexString == null) { throw new ArgumentNullException($"{nameof(hexString)}"); } int startIndex = hexString.StartsWith("0x") ? 2 : 0; int numberChars = hexString.Length - startIndex; Nibble[] nibbles = new Nibble[numberChars]; for (int i = 0; i < numberChars; i++) { nibbles[i] = new Nibble(hexString[i + startIndex]); } return(nibbles); }
public static byte ToByte(Nibble highNibble, Nibble lowNibble) { return((byte)(((byte)highNibble << 4) | (byte)lowNibble)); }