Given a number in hex, 0x1234
to extract an individual digit, you need to do bitwise manipulations.
int x = 0x1234; int third = (x >> (2*4)) & 0xf; assert (third == 0x2);
The ">>" shift operator moves the number to the right by the specified number of bits. So:
01001000110100b 0x1234
>> 8 >> 0x0008
------------------ ---------
010010b 0x0012
The "&" integer bitwise operator masks the number. So:
00010010b 0x0012 & 00001111b & 0x000f ----------- -------- 00000010b 0x0002