Why use hexadecimal values ​​instead of normal base 10 numbers?

I looked at this code for calculation math.sqrtin Java. Why did they use hexadecimal values ​​in some loops and normal values ​​for variables? What is the use of using hex?

+5
source share
3 answers

Because the hexadecimal value is much closer to the bits, which are decimal numbers. Each hexadecimal digit corresponds to 4 bits (nibble). So, once you recognize the bitmask associated with each hexadecimal digit (0-F), you can do something like “I want a mask for the low byte”:

0xff

" 31 ":

0x7fffffff

:

HEX    BIN
0   -> 0000
1   -> 0001
2   -> 0010
3   -> 0011
4   -> 0100
5   -> 0101
6   -> 0110
7   -> 0111
8   -> 1000
9   -> 1001
A   -> 1010
B   -> 1011
C   -> 1100
D   -> 1101
E   -> 1110
F   -> 1111
+27

, , , . , 0x7fffffff 2147483647, .

+3

Hex - , . ,

+2

All Articles