java - Extracting 3rd digit of a hexadecimal number -
i want extract 3rd digit of hex number. example, extract 4
0x4598
.
to extract 0th digit:
(0x4598 & 0x0f) // returns 8
to extract 1st digit:
(0x4598 & 0xf0) >> 4 // returns 9
to extract 2nd digit:
(0x4598 & 0xf00) >> 8 // returns 5
for 3rd digit, followed pattern , tried (0x4598 & 0xf000) >> 16
, returns 0
. wrong?
the pattern here add four, not double.
try instead:
(0x4598 & 0xf000) >> 12;
Comments
Post a Comment