Java Reference
In-Depth Information
F.3 Conversions Between Hexadecimal and Decimal
Numbers
Given a hexadecimal number
h
n
h
n
-
1
h
n
-
2
c
h
2
h
1
h
0
, the equivalent decimal value is
h
n
hex to decimal
16
n
16
n
-
1
16
n
-
2
16
2
16
1
16
0
*
+
h
n
-
1
*
+
h
n
-
2
*
+ c +
h
2
*
+
h
1
*
+
h
0
*
Here are some examples of converting hexadecimal numbers to decimals:
Hexadecimal
Conversion Formula
Decimal
7F
16
1
16
0
127
*
+
*
7
15
FFFF
16
3
16
2
16
1
16
0
65535
15
*
+
15
*
+
15
*
+
15
*
431
16
2
16
1
16
0
1073
4
*
+
3
*
+
1
*
To convert a decimal number
d
to a hexadecimal number is to find the hexadecimal digits
h
n
,
h
n
-
1
,
h
n
-
2
,
c
,
h
2
,
h
1
, and
h
0
such that
decimal to hex
16
n
16
n
-
1
16
n
-
2
16
2
=
*
+
*
+
*
+ c +
*
d
h
n
h
n
-
1
h
n
-
2
h
2
16
1
16
0
+
*
+
*
h
1
h
0
These numbers can be found by successively dividing
d
by 16 until the quotient is 0. The
remainders are
h
0
,
h
1
,
h
2
,
c
,
h
n
-
2
,
h
n
-
1
, and
h
n
.
For example, the decimal number 123 is 7B in hexadecimal. The conversion is done as
follows:
0
7
Quotient
16
7
0
7
16
123
112
11
Remainder
h
1
h
0
F.4 Conversions Between Binary and Hexadecimal
Numbers
To convert a hexadecimal to a binary number, simply convert each digit in the hexadecimal
number into a four-digit binary number, using Table F.1.
hex to binary
For example, the hexadecimal number 7B is 1111011, where 7 is 111 in binary, and B is
1011 in binary.
To convert a binary number to a hexadecimal, convert every four binary digits from right
to left in the binary number into a hexadecimal number.
For example, the binary number 1110001101 is 38D, since 1101 is D, 1000 is 8, and 11 is
3, as shown below.
binary to hex
1 1 1000 1101
3
8
D
Search WWH ::
Custom Search