﻿ Java Tutorial
﻿

Main Page

When we get to larger binary numbers, for example:

1111 0101 1011 1001 1110 0001

the notation starts to be a little cumbersome, particularly when you consider that if you apply the same method to work out what this in decimal, it's only 16,103,905, a miserable 8 decimal digits. You can sit more angels on a pinhead than that. Well, as it happens, we have an excellent alternative.

Arithmetic to base 16 is a very convenient option. Each digit can have values from 0 to 15 (the digits from 10 to 15 being represented by the letters A to F as shown in the next figure) and values from 0 to 15 correspond quite nicely with the range of values that four binary digits can represent.

Decimal

Binary

0

0

0000

1

1

0001

2

2

0010

...

...

...

9

9

1001

A

10

1010

B

11

1011

C

12

1100

D

13

1101

E

14

1110

F

15

1111

Since a hexadecimal digit corresponds exactly to 4 binary bits, we can represent the binary number above as a hexadecimal number just by taking successive groups of four binary digits starting from the right, and writing the equivalent base 16 digit for each group. The binary number:

1111 0101 1011 1001 1110 0001

will therefore come out as:

F5B9E1

We have six hexadecimal digits corresponding to the six groups of four binary digits. Just to show it all works out with no cheating, we can convert this number directly from hexadecimal to decimal, by again using the analogy with the meaning of a decimal number, as follows:

F5B9E1 is:

15 x 16 x 16 x 16 x 16 x 16 + 5 x 16 x 16 x 16 x 16 + 11 x 16 x 16 x 16 + 9 x 16 x 16 + 14 x16 + 1

This in turn turns out to be:

15,728,640 + 327,680+ 45,056 + 2304 + 224 + 1

which fortunately totals to the same number we got when we converted the equivalent binary number to a decimal value.

JavaScript Editor Java Tutorials Free JavaScript Editor

﻿