Computers use binary numbers internally, because computers are made
naturally to store and
process 0s and 1s. The binary number system has two digits, 0 and 1. A number or character
is stored as a sequence of 0s and 1s. Each 0 or 1 is called a *bit*
(binary digit).

In our daily life we use decimal numbers. When we write a number such as 20 in a program, it is assumed to be a decimal number. Internally, computer software is used to convert decimal numbers into binary numbers, and vice versa.

We write computer programs using decimal numbers. However, to deal with an operating system, we need to reach down to the "machine level" by using binary numbers. Binary numbers tend to be very long and cumbersome. Often hexadecimal numbers are used to abbreviate them, with each hexadecimal digit representing four binary digits. The hexadecimal number system has 16 digits: 0-9 and A-F. The letters A, B, C, D, E, and F correspond to the decimal numbers 10, 11, 12, 13, 14, and 15.

The digits in the decimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. A decimal number is represented by a sequence of one or more of these digits. The value that each digit represents depends on its position, which denotes an integral power of 10. For example, the digits 7, 4, 2, and 3 in decimal number 7423 represent 7000, 400, 20, and 3, respectively, as shown below:

7423
= 7 × 10^{3} + 4 × 10^{2} + 2 × 10^{1} + 3 ×
10^{0}

10^{3} 10^{2} 10^{1} 10^{0} = 7000 + 400 + 20 + 3 = 7423

The decimal number system has ten digits, and the position values are integral powers of 10.
We say that 10 is the *base* or *radix* of the decimal number system. Similarly, since the
binary
number system has two digits, its base is 2, and since the hex number system has 16 digits,
its base is 16.

If 1101 is a binary number, the
digits 1, 1, 0, and 1 represent 1 × 2^{3}, 1 × 2^{2}, 0 ×
2^{1}, and 1 × 2^{0},respectively:

1101
= 1 × 2^{3} + 1 × 2^{2} + 0 × 2^{1} + 1 ×
2^{0}

2^{3} 2^{2} 2^{1}
2^{0} = 8 + 4 + 0 + 1 = 13

If 7423 is a hex number, the digits
7, 4, 2, and 3 represent 7 × 16^{3}, 4 × 16^{2}, 2 ×
16^{1}, and 3 × 16^{0},respectively:

7423
= 7 × 16^{3} + 4 × 16^{2} + 2 × 16^{1} + 3 ×
16^{0}

16^{3} 16^{2} 16^{1} 16^{0} = 7000 + 400 + 20 + 3 = 7423

Given a binary number b_{n}b_{n - 1}b_{n -
2}...b_{2}b_{1}b_{0}, the equivalent decimal value is
b_{n} × 2^{n} + b_{n-1} × 2^{n-1} +
b_{n-2} × 2^{n-2} + ... +
b_{2} × 2^{2} + b_{1} × 2^{1} + b_{0} ×
2^{0}.

Here are some examples of converting binary numbers to decimals:

*Binary:*10*Conversion Formula:*1 × 2^{1}+ 0 × 2^{0}*Decimal:*2*Binary:*1000*Conversion Formula:*1 × 2^{3}+ 0 × 2^{2}+ 0 × 2^{1}+ 0 × 2^{0}*Decimal:*8*Binary:*10101011*Conversion Formula:*1 × 2^{7}+ 0 × 2^{6}+ 1 × 2^{5}+ 0 × 2^{4}+ 1 × 2^{3}+ 0 × 2^{2}+ 1 × 2^{1}+ 1 × 2^{0}*Decimal:*171

To convert a decimal number d to a binary number is to find the bits b_{n}b_{n - 1}b_{n -
2}...b_{2}b_{1}b_{0} such that

d = b_{n} × 2^{n} + b_{n-1} × 2^{n-1} + b_{n-2} ×
2^{n-2} + ... +
b_{2} × 2^{2} + b_{1} × 2^{1} + b_{0} ×
2^{0}

These bits can be found by successively dividing d by 2 until the quotient is 0. The remainders
are b_{0}b_{1}b_{2}...b_{n - 2}b_{n - 1}b_{n}.

For example, the decimal number 123 is 1111011 in binary. The conversion is done as follows:

2 | 123 | |

2 | 61 | 1 |

2 | 30 | 1 |

2 | 15 | 0 |

2 | 7 | 1 |

2 | 3 | 1 |

1 | 1 |

Than count Binary number bottom to Up. 1111011

Given a hexadecimal number h_{n}h_{n - 1}h_{n -
2}...h_{2}h_{1}h_{0}, the equivalent decimal value is
h_{n} × 16^{n} + h_{n-1} × 16^{n-1} +
h_{n-2} × 16^{n-2} + ... +
h_{2} × 16^{2} + h_{1} × 16^{1} + h_{0} ×
16^{0}.

Here are some examples of converting hexadecimal numbers to decimals:

*Hexadecimal:*7F*Conversion Formula:*7 × 16^{1}+ 15 × 16^{0}*Decimal:*127*Hexadecimal:*FFFF*Conversion Formula:*15 × 16^{3}+ 15 × 16^{2}+ 15 × 16^{1}+ 15 × 16^{0}*Decimal:*65535*Hexadecimal:*431*Conversion Formula:*4 × 16^{2}+ 3 × 16^{1}+ 1 × 16^{0}*Decimal:*1073

To convert a decimal number d to a hexadecimal number is to find the bits h_{n}h_{n -
1}h_{n - 2}...h_{2}h_{1}h_{0} such that

d = h_{n} × 16^{n} + h_{n-1} × 16^{n-1} + h_{n-2} ×
16^{n-2} + ... +
h_{2} × 16^{2} + h_{1} × 16^{1} + h_{0} ×
16^{0}

These bits can be found by successively dividing d by 16 until the quotient is 0. The remainders
are h_{0}h_{1}h_{2}...h_{n - 2}h_{n - 1}h_{n}.

For example, the decimal number 123 is 7B in hexadecimal. The conversion is done as follows:

16 | 123 | |

16 | 7 | 11 |

0 | 7 |

Than count Hexadecimal number bottom to Up. 7B

To convert a hexadecimal to a binary number, simply convert each digit in the hexadecimal number into a four-digit binary number, using Table

Hexadecimal | Binary | Decimal | Octal |
---|---|---|---|

0 | 0000 | 0 | 0 |

1 | 0001 | 1 | 1 |

2 | 0010 | 2 | 2 |

3 | 0011 | 3 | 3 |

4 | 0100 | 4 | 4 |

5 | 0101 | 5 | 5 |

6 | 0110 | 6 | 6 |

7 | 0111 | 7 | 7 |

8 | 1000 | 8 | 10 |

9 | 1001 | 9 | 11 |

A | 1010 | 10 | 12 |

B | 1011 | 11 | 13 |

C | 1100 | 12 | 14 |

D | 1101 | 13 | 15 |

E | 1110 | 14 | 16 |

F | 1111 | 15 | 17 |

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.