@Test public void testInt2NibbleMap() { int i; byte[] expectedHex = new byte[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f'}; int[] controlInts = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}; for (i = 0; i < controlInts.length; i++) { assertEquals(BitConverters.nibble2Int(expectedHex[i]), controlInts[i]); } }
public static int nibble2Int(byte nibble) { int out; switch (nibble) { case '0': out = 0; break; case '1': out = 1; break; case '2': out = 2; break; case '3': out = 3; break; case '4': out = 4; break; case '5': out = 5; break; case '6': out = 6; break; case '7': out = 7; break; case '8': out = 8; break; case '9': out = 9; break; case 'a': out = 10; break; case 'b': out = 11; break; case 'c': out = 12; break; case 'd': out = 13; break; case 'e': out = 14; break; case 'f': out = 15; break; case 'A': out = 10; break; case 'B': out = 11; break; case 'C': out = 12; break; case 'D': out = 13; break; case 'E': out = 14; break; case 'F': out = 15; break; default: out = -1; break; } return out; }
BitConverters { public static int nibble2Int(byte nibble) { int out; switch (nibble) { case '0': out = 0; break; case '1': out = 1; break; case '2': out = 2; break; case '3': out = 3; break; case '4': out = 4; break; case '5': out = 5; break; case '6': out = 6; break; case '7': out = 7; break; case '8': out = 8; break; case '9': out = 9; break; case 'a': out = 10; break; case 'b': out = 11; break; case 'c': out = 12; break; case 'd': out = 13; break; case 'e': out = 14; break; case 'f': out = 15; break; case 'A': out = 10; break; case 'B': out = 11; break; case 'C': out = 12; break; case 'D': out = 13; break; case 'E': out = 14; break; case 'F': out = 15; break; default: out = -1; break; } return out; } }
BitConverters { public static int nibble2Int(byte nibble) { int out; switch (nibble) { case '0': out = 0; break; case '1': out = 1; break; case '2': out = 2; break; case '3': out = 3; break; case '4': out = 4; break; case '5': out = 5; break; case '6': out = 6; break; case '7': out = 7; break; case '8': out = 8; break; case '9': out = 9; break; case 'a': out = 10; break; case 'b': out = 11; break; case 'c': out = 12; break; case 'd': out = 13; break; case 'e': out = 14; break; case 'f': out = 15; break; case 'A': out = 10; break; case 'B': out = 11; break; case 'C': out = 12; break; case 'D': out = 13; break; case 'E': out = 14; break; case 'F': out = 15; break; default: out = -1; break; } return out; }  }
BitConverters { public static int nibble2Int(byte nibble) { int out; switch (nibble) { case '0': out = 0; break; case '1': out = 1; break; case '2': out = 2; break; case '3': out = 3; break; case '4': out = 4; break; case '5': out = 5; break; case '6': out = 6; break; case '7': out = 7; break; case '8': out = 8; break; case '9': out = 9; break; case 'a': out = 10; break; case 'b': out = 11; break; case 'c': out = 12; break; case 'd': out = 13; break; case 'e': out = 14; break; case 'f': out = 15; break; case 'A': out = 10; break; case 'B': out = 11; break; case 'C': out = 12; break; case 'D': out = 13; break; case 'E': out = 14; break; case 'F': out = 15; break; default: out = -1; break; } return out; }  static String int16bit2hex(int i16); static int hex16bit2int(String in); static int nibble2Int(byte nibble); static byte int2Nibble(int in); static int ubyte2int(byte in); static byte int2ubyte(int in); static String byte2hex(byte ubyte); static byte[] uint2bytes(int in); static String bytes2hex(byte[] bytes); }
BitConverters { public static int nibble2Int(byte nibble) { int out; switch (nibble) { case '0': out = 0; break; case '1': out = 1; break; case '2': out = 2; break; case '3': out = 3; break; case '4': out = 4; break; case '5': out = 5; break; case '6': out = 6; break; case '7': out = 7; break; case '8': out = 8; break; case '9': out = 9; break; case 'a': out = 10; break; case 'b': out = 11; break; case 'c': out = 12; break; case 'd': out = 13; break; case 'e': out = 14; break; case 'f': out = 15; break; case 'A': out = 10; break; case 'B': out = 11; break; case 'C': out = 12; break; case 'D': out = 13; break; case 'E': out = 14; break; case 'F': out = 15; break; default: out = -1; break; } return out; }  static String int16bit2hex(int i16); static int hex16bit2int(String in); static int nibble2Int(byte nibble); static byte int2Nibble(int in); static int ubyte2int(byte in); static byte int2ubyte(int in); static String byte2hex(byte ubyte); static byte[] uint2bytes(int in); static String bytes2hex(byte[] bytes);  }