Hex digits are very easy to get: to access the value of the digit k
, counting from right, shift the value right by 4*k
, and mask with & 0x0F
.
int n= 0x234;
int digit2 = (n >> 2*4) & 0x0F; // Gives you 2
int digit1 = (n >> 1*4) & 0x0F; // Gives you 3
int digit0 = (n >> 0*4) & 0x0F; // Gives you 4