Information is represented electronically in a computer using voltages of different levels. For instance, a 0 could be represented by a 0 voltage and a 1 could be represented by a voltage of 3 volts. In principle, one could design a computer to use a large set of voltage levels; in practice, only two are used. This is because the closer the voltage levels are to each other, the greater the chance of distorting data due to voltage drift and noise. As an example, suppose that voltages which differ by 1 volt are used to represent consecutive integers. If the power supply output changes by .5 volts, it is impossible to determine whether a 2.5 volt level represents a 2 or a 3. In addition, as computers become faster, the voltage levels must be smaller to avoid overheating. As a result, we restrict ourselves to two voltage levels, which means that each piece of information in a computer can only represent the values 0 or 1.

Human beings commonly have 10 fingers, which has led to the adoption of the decimal (or base 10) number system
as the common language of arithmetic. Just as in base 10 digits may take the values 0 through 9, in an
arbitrary base "n" (where n is a positive integer), the digits may take values from 0 to "n-1"; hence in base 2
(the **binary** number system) the digits may take the values 0 or 1. For this reason, information in a
computer is represented in binary, and each piece of information is called a **bit** (binary digit).

2^{0}= 1

2^{1}= 2

2^{2}= 4

2^{3}= 8

2^{4}= 16

2^{5}= 32

2^{6}= 64

2^{7}= 128

2^{8}= 256

2^{9}= 512

2^{10}= 1,024

2^{11}= 2,048

2^{12}= 4,096

2^{13}= 8,192

2^{14}= 16,384

2^{15}= 32,768

2^{16}= 65,536

1 1 0 1 0(we will denote binary numbers using the subscript 2;_{2}

16 + 8 + 2 = 26.In converting a large binary number to decimal, it is often useful to write the place values above the bits, and simply add together all of the place values which have a 1. Since the place values are simply powers of 2, each consecutive place value is obtained by doubling the previous one. Suppose we wish to find the decimal equivalent of the binary number 1 0 1 1 0 1 1 1 0 1 0 1

Some large binary numbers have prefixes associated with them similar to the metric prefixes commonly used in the decimal number system. Unfortunately, the use of these prefixes is not entirely consistent. The metric prefixes "Kilo", "Mega", "Giga" and "Tera" stand for 10

2 1 0 0 5 2 1 4 2 1 5 2 6 3 1 8 4 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - - - 1 0 1 1 0 1 1 1 0 1 0 1 2,048 + 512 + 256 + 64 + 32 + 16 + 4 + 1 = 2,933.

Kilo = 2Additional confusion arises when the vendors of computer equipment such as hard drives use metric prefixes instead of the more usual binary prefixes in order to make their product appear to have a larger capacity.^{10}= 1,024

Mega = 2^{20}= 1,048,576

Giga = 2^{30}= 1,073,741,824

Tera = 2^{40}= 1,099,511,627,776

Peta = 2^{50}= 1,125,899,906,842,624

Exa = 2^{60}= 1,152,921,504,606,846,976

Zetta = 2^{70}= 1,180,591,620,717,411,303,424

Yotta = 2^{80}= 1,208,925,819,614,629,174,706,176

As an example we will convert decimal 763 into binary:

- Identify the largest power of 2 which is less than or equal to the number.
- Write down all the binary place values from that power of 2 to 1.
- Put a 1 in the place corresponding to that power of 2.
- Subtract that power of 2 from the decimal number.
- Identify the largest power of 2 which is less than or equal to the new number.
- Repeat the last three steps until the new number is 0.
- Put 0's in all of the remaining places.

- Having memorized our powers of 2, we immediately recognize that the largest power of 2 which is less than or equal to 763 is 512.

- We then write down all the binary place values from 512 to 1:

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - -

- We put a 1 in the 512's place:
and subtract 512 from 763 to get 251.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1

- The largest power of 2 which is less than or equal to 251 is 128, so we put a 1 in the 128's place:
and subtract 128 from 251 to get 123.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 1

- The largest power of 2 which is less than or equal to 123 is 64, so we put a 1 in the 64's place:
and subtract 64 from 123 to get 59.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 1 1

- The largest power of 2 which is less than or equal to 59 is 32, so we put a 1 in the 32's place:
and subtract 32 from 59 to get 27.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 1 1 1

- The largest power of 2 which is less than or equal to 27 is 16, so we put a 1 in the 16's place:
and subtract 16 from 27 to get 11.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 1 1 1 1

- The largest power of 2 which is less than or equal to 11 is 8, so we put a 1 in the 8's place:
and subtract 8 from 11 to get 3.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 1 1 1 1 1

- The largest power of 2 which is less than or equal to 3 is 2, so we put a 1 in the 2's place:
and subtract 2 from 3 to get 1.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 1 1 1 1 1 1

- The largest power of 2 which is less than or equal to 1 is 1, so we put a 1 in the 1's place:
and subtract 1 from 1 to get zero.

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 1 1 1 1 1 1 1

- We now put 0's in the remaining places:
and find that decimal 763 is 1011111011

5 2 1 1 5 2 6 3 1 2 6 8 4 2 6 8 4 2 1 - - - - - - - - - - 1 0 1 1 1 1 1 0 1 1 _{2}

This algorithm has the advantages of reinforcing your binary "numeracy" (numerical literacy), and since on the average, half of the digits in a binary number are 0, requiring fewer steps than other more mechanical algorithms. You should of course convert the binary result back into decimal as we did above, as a check that we did not make a mistake.

The binary number system obviously poses problems for the ordinary human, yet it is the only way to represent numbers inside the computer. By choosing to work in a number system whose base is larger but still a power of 2, we can simplify numbers from a human point of view while retaining an accurate representation of what goes on inside the computer. Both

1 1 _{2}10 1010 _{2}100 1100100 _{2}1,000 1111101000 _{2}10,000 10011100010000 _{2}100,000 11000011010100000 _{2}1,000,000 11110100001001000000 _{2}

Since hexadecimal is base 16, it must have single digits with values from 0 to 15. Hexadecimal digits representing values from 0 to 9 are obvious, and the letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15. You should memorize the binary values of all of the hexadecimal digits, and the decimal values of powers of 16 from 0 to 4:

0It is worth noting that since 16 is 2_{16}= 0 0 0 0_{2}

1_{16}= 0 0 0 1_{2}

2_{16}= 0 0 1 0_{2}

3_{16}= 0 0 1 1_{2}

4_{16}= 0 1 0 0_{2}

5_{16}= 0 1 0 1_{2}

6_{16}= 0 1 1 0_{2}

7_{16}= 0 1 1 1_{2}

8_{16}= 1 0 0 0_{2}

9_{16}= 1 0 0 1_{2}

A_{16}= 1 0 1 0_{2}

B_{16}= 1 0 1 1_{2}

C_{16}= 1 1 0 0_{2}

D_{16}= 1 1 0 1_{2}

E_{16}= 1 1 1 0_{2}

F_{16}= 1 1 1 1_{2}16

^{0}= 1

16^{1}= 16

16^{2}= 256

16^{3}= 4,096

16^{4}= 65,536

Conversion between binary and hexadecimal numbers is easy since we have memorized the hexadecimal digits in
binary: we simply group the binary digits in groups of four, starting from the least significant bit, and
translate into hexadecimal (inserting **leading zeroes** in front if we feel the need):

1 0001_{2}1 _{16}10 1010_{2}A _{16}100 0110 0100_{2}64 _{16}1,000 0011 1110 1000_{2}3E8 _{16}10,000 0010 0111 0001 0000_{2}2710 _{16}100,000 0001 1000 0110 1010 0000_{2}186A0 _{16}1,000,000 1111 0100 0010 0100 0000_{2}F4240 _{16}

As an example we will convert decimal 763 into hexadecimal:

- Identify the largest power of 16 which is less than or equal to the number.
- Write down all the hexadecimal place values from that power of 16 to 1.
- Divide the number by that power of 16.
- Put the quotient in the place corresponding to that power of 16.
- Identify the largest power of 16 which is less than or equal to the remainder.
- Repeat the last three steps until the new number is 0.
- Put 0's in all of the remaining places.

You should convert this answer to both decimal and binary in order to verify that our algorithms produce consistent results.

- Having memorized our powers of 16, we immediately recognize that the largest power of 16 which is less than or equal to 763 is 256.

- We then write down all the hexadecimal place values from 256 to 1:

2 5 1 6 6 1 - - -

- We divide 763 by 256 to get 2 with a remainder of 251, so we put a 2 in the 256's place:

2 5 1 6 6 1 - - - 2

- The largest power of 16 which is less than or equal to 251 is 16, so we divide 251 by 16 to get a quotient of 15 with the remainder of 11. We then put an F (hexadecimal for 15) in the 16's place:

2 5 1 6 6 1 - - - 2 F

- The largest power of 16 which is less than or equal to 11 is 1, so we put a B (hexadecimal for 11) in the 1's place:

2 5 1 6 6 1 - - - 2 F B

- Since all of the places have nonzero hexadecimal digits, the algorithm is finished and the answer is 2FB
_{16}.

Now that we are familiar with the binary and hexadecimal number systems, we need to learn how to do Binary and Hexdecimal Arithmetic.

Go to: Title Page Table of Contents Index

©2013, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.

Please send comments or suggestions to the author.