17 int c = (byte)((value >> 4) | ((value & 0xf) << 4));
18 c = ((c & 0xcc) >> 2) | ((c & 0x33) << 2);
19 c = ((c & 0xaa) >> 1) | ((c & 0x55) << 1);
28 public static bool IsHex(
this char c) => (c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f' || c >=
'A' && c <=
'F');
36 public static int HexToInt(
this char value) => value
switch
38 { } c when (c >=
'0' && c <=
'9') => (byte)(c -
'0'),
39 { } c when (c >=
'A' && c <=
'F') => (byte)(c -
'A' + 10),
40 { } c when (c >=
'a' && c <=
'f') => (byte)(c -
'a' + 10),
41 _ =>
throw new InvalidOperationException(
"Not a valid hex string")
Extension methods for helping with binary conversion.
static bool IsHex(this char c)
Tests to see if character is a valid hex digit.
static int HexToInt(this char value)
Converts a single hex digit character to its integer representation.
static byte ReverseBits(this byte value)
Reverse the bits of a single byte.