Number Systems
created by professor robert solis
1
Different types of numbering systems
• Decimal
- All existing numbers in the decimal system include.
- 0123456789
• Binary
- All existing numbers in the binary system include
-01
• Hexadecimal
- All existing numbers in the hexadecimal system include
- 0123456789ABCDEF
• Octal
- All existing numbers in the octal system include
- 01234567
2
Binary numbering system
• A binary number can only be one of two values (i.e., 1
or 0)
• A binary number is like a switch on the wall
(on = 1, off = 0)
This switch is on
This switch is off
3
Binary numbering system
• How many outcomes are possible with two switches?
off off off on
on off on on
4
Binary numbering system
• Instead of switches, let's use binary numbers 1 and 0
• Let the number 1 represent on.
• Let the number 0 represent off.
2nd Binary Digit 1st Binary Digit
0 0
4 Possibilities
0 1
1 0
1 1
5
Binary numbering system
• How many outcomes are possible with three switches?
3rd binary digit 2nd binary digit 1st binary digit
0 0 0
0 0 1
0 1 0
8 Possibilities
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
6
Binary Numbering System
• Did you notice that...
1 switch generates 2 possible outcomes
2 switches generate 4 possible outcomes
3 switches generate 8 possible outcomes
• What mathematical function is apparent here?
2 n
7
Binary Numbering System
• Given n binary numbers, 2n determines the number of
possible outcomes.
n (# of binary numbers) 2n (# of possible outcomes)
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
8
Converting Binary to Decimal Numbers
• Now that you know what binary numbers look like let’s
see how to convert them into decimal numbers.
• A decimal number is a numbering system that uses the
following numbers: 0 1 2 3 4 5 6 7 8 9
• Given the binary number 1001, how do we convert it to
a decimal number?
Decimal value 32 16 8 4 2 1
2n 25 24 23 22 21 20
position 6th 5th 4th 3rd 2nd 1st
9
Converting Binary to Decimal Numbers
• To determine the value of a binary number you must
do the following.
Sum of decimal values
Decimal value 8 0 0 1 8+0+0+1=9
Binary number * 2n 1 * 23 0 * 22 0 * 21 1 * 20
Binary number 1 0 0 1
• Therefore binary 1001 equals decimal 9.
10
Converting Binary to Decimal Numbers
• Let’s try it again. Determine the decimal value of binary
1111.
Sum of decimal values
Decimal value 8 4 2 1 8 + 4 + 2 + 1 = 15
Binary number * 2n 1 * 23 1 * 22 1 * 21 1 * 20
Binary number 1 1 1 1
• Therefore binary 1111 equals decimal 15.
11
Converting Binary to Decimal Numbers
• Let’s try it again. Determine the decimal value of binary
1010.
Sum of decimal values
Decimal value 8 0 2 0 8 + 0 + 2 + 0 = 10
Binary number * 2n 1 * 23 0 * 22 1 * 21 0 * 20
Binary number 1 0 1 0
• Therefore binary 1010 equals decimal 10.
12
Converting Decimal to Binary Numbers
• How do you convert decimal numbers into binary
numbers?
• Convert decimal 135 into a binary number.
Decimal value 128 64 32 16 8 4 2 1
Sum of 135 = 128+ 4+ 2+ 1
Binary number 1 0 0 0 0 1 1 1
• Therefore decimal 135 is 10000111 binary.
13
Converting Decimal to Binary Numbers
• Convert decimal 175 into a binary number.
Decimal value 128 64 32 16 8 4 2 1
Sum of 175 = 128+ 32+ 8+ 4+ 2+ 1
Binary number 1 0 1 0 1 1 1 1
• Therefore decimal 175 is 10101111 binary.
14
Hexadecimal Numbers
• Another popular numbering system that is used in the realm of
computers and software is call hexadecimal.
• The hexadecimal numbering system has 16 numbers.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
• Typically hexadecimal numbers have the suffix “H”. For example,
- 24A9H
• The suffix “H” prevents any confusion when determining if a number is
hexadecimal or decimal. For example,
- 2345 is a decimal number, 2345H is a hexadecimal number.
15
Converting Hexadecimal into Binary
• Consider the following hexadecimal to binary conversion table.
Binary Hexadecimal Decimal Binary Hexadecimal Decimal
0000 0 0 1000 8 8
0001 1 1 1001 9 9
0010 2 2 1010 A 10
0011 3 3 1011 B 11
0100 4 4 1100 C 12
0101 5 5 1101 D 13
0110 6 6 1110 E 14
0111 7 7 1111 F 15
16
Converting Hexadecimal into Binary
• Consider the following example of how to convert hexadecimal number
9A35H into a binary number.
Hexadecimal 9 A 3 5
Binary 1001 1010 0011 0101
• Notice that each hexadecimal number is converted to it’s
corresponding binary value.
• Note that each hexadecimal value must be converted to a group of four
binary numbers
• Leading zeroes must be added if the hexadecimal number is less than
eight (e.g., 0011 binary = 3H, 0101 binary = 5H).
17
Converting Binary into Hexadecimal
• Now that we know how to convert hexadecimal numbers into binary
numbers, we’ll reverse the process for converting binary numbers into
hexadecimal numbers.
• Simply group the binary number into groups of four digits (from right to
left) and convert each group into a hexadecimal number.
• Use leading zeroes for groups that don’t have four digits. For example,
- 1111010110100001 <<< Original binary number
- 1111 0101 1010 0001 <<< Grouped binary number
-F 5 A 1 <<< Converted into hexadecimal
18
Hexadecimal to Decimal Conversion
• The process of converting a hexadecimal number to a
decimal number requires one extra step.
• Convert from hexadecimal to binary, then from binary
to decimal.
• Consider the following step by step example of how to
convert the hexadecimal number F7H to decimal.
19
Hexadecimal to Decimal Conversion
• Step 1: Convert F7H to binary. Write four binary
number positions for each hex number.
F 7
8 4 2 1 8 4 2 1
20
Hexadecimal to Decimal Conversion
• Step 2: Fill in the binary numerical values for each
hexadecimal number.
F 7
8 4 2 1 8 4 2 1
1 1 1 1 0 1 1 1
21
Hexadecimal to Decimal Conversion
• Step 3: Treat all the sets of binary numbers as one
connected binary number.
F 7
128 64 32 16 8 4 2 1
1 1 1 1 0 1 1 1
22
Hexadecimal to Decimal Conversion
• Step 4: Convert to decimal.
128 64 32 16 8 4 2 1
1 1 1 1 0 1 1 1
128+ 64+ 32+ 16+ 0+ 4+ 2+ 1=
247
23
Decimal to Hexadecimal Conversion
• The process of converting a decimal number to a
hexadecimal number requires one extra step.
• Convert from decimal to binary, then from binary to
hexadecimal.
• Consider the following step by step example of how to
convert the decimal number 135 to hexadecimal.
24
Decimal to Hexadecimal Conversion
• Step 1: Convert 135 to binary. Write the necessary
binary positions to accommodate the entire number.
128 64 32 16 8 4 2 1
25
Decimal to Hexadecimal Conversion
• Step 2: Activate those numbers that add up to 135.
128 64 32 16 8 4 2 1
1 0 0 0 0 1 1 1
26
Decimal to Hexadecimal Conversion
• Step 3: Split the binary number into groups of four
starting from the right hand side.
128 64 32 16 8 4 2 1
1 0 0 0 0 1 1 1
128 64 32 16 8 4 2 1
1 0 0 0 0 1 1 1
• Note: Add prefix zeros if the last group does not have
enough binary digits to create a group of four.
27
Decimal to Hexadecimal Conversion
• Step 4: Change the numerical position values for each
group to 8 4 2 1.
8 4 2 1 8 4 2 1
1 0 0 0 0 1 1 1
28
Decimal to Hexadecimal Conversion
• Step 5: Convert each group to a hexadecimal number
8 4 2 1 8 4 2 1
1 0 0 0 0 1 1 1
8 7
• The final answer must include an H to indicate that it is
a hexadecimal number. Therefore the answer is 87H.
29
Adding Binary
Numbers
30
Adding Binary Numbers
• One thing to remember when adding binary numbers
together is that the result is either a 0 or a 1.
• The result of binary 1 + 1 is 10.
• This is not ten, rather it is "one zero"
• Consider the same problem, from a vertical layout.
+1
10
31
Adding Binary Numbers
• Example: Add binary 110 with 111.
• Step 1: Arrange the problem vertically.
• Step 2: Add the first two numbers.
110
111
1
32
Adding Binary Numbers
• Step 3: Add the next two numbers.
Carry the 1
1
110
111
01
33
Adding Binary Numbers
• Step 4: Add the next two numbers.
Carry the 1
1
110
111
1101
34
Adding Binary Numbers
• As a verification we can convert the binary numbers to
decimal, add them, and then determine if the sum is
correct.
Binary Decimal
110 6
111 7
1101 13
35