Number Systems
How Computer
Represents Data
Language of 0’s and 1’s
Objectives
Understand why computers use binary (Base-2)
numbering.
Understand how to convert Base-2 numbers to Base-
10 or Base-8.
Understand how to convert Base-8 numbers to Base-
10 or Base 2.
Understand how to convert Base-16 numbers to
Base-10, Base 2 or Base-8.
Two State Model
• Computer stores data/information as zeros and ones
• Called Bit (Binary Integer)
• A Bit can have two different states (0 or 1)
• Any system that has two states can be thought of as a
bit:
• 0 or 1
• off or on
• yes or no
• true or false
• high or low
• open or closed
Why Binary System?
• Computers are made of a series of
switches
• Each switch has two states: ON or OFF
• Each state can be represented by a
number – 1 for “ON” and 0 for “OFF”
Binary Numbers and Computers
Computers have storage units called binary digits or
bits
Low Voltage = 0
High Voltage = 1 all bits have 0 or 1
22
Characteristics of Numbering Systems
1) The digits are consecutive.
2) The number of digits is equal to the size of the
base.
3) Zero is always the first digit.
4) The base number is never a digit.
5) When 1 is added to the largest digit, a sum of zero
and a carry of one results.
6) Numeric values are determined by the implicit
positional values of the digits.
Number systems include decimal, binary,
octal and hexadecimal
Number System Base Symbol
Binary Base 2 B
Octal Base 8 O
Decimal Base 10 D
Hexadecimal Base 16 H
Common Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
Conversion Among Bases
• The possibilities:
Decimal Octal
Binary Hexadecimal
Decimal Octal
Binary Hexadecimal
Weight
12510 => 5 x 100 = 5
2 x 101 = 20
1 x 102 = 100
125
Base
Decimal to Binary
Decimal Octal
Binary Hexadecimal
Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant bit)
– Second remainder is bit 1
– Etc.
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
Decimal to Binary
Repeated Division By 2
• For this method, divide the decimal number by 2,
• If the remainder is 0, on the right side write down
a 0.
• If the remainder is 1, write down a 1.
• When performing the division, the remainders
which will represent the binary equivalent of the
decimal number are written beginning at the least
significant digit (right) and each new digit is
written to more significant digit (the left) of the
previous digit.
16
Decimal to Octal
Decimal Octal
Binary Hexadecimal
Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder
Example
123410 = ?8
8 1234
8 154 2
8 19 2
8 2 3
0 2
123410 = 23228
Decimal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder
Example
123410 = ?16
16 1234
16 77 2
16 4 13 = D
0 4
123410 = 4D216
Binary to Decimal
Decimal Octal
Binary Hexadecimal
Binary to Decimal
• Technique
– Multiply each bit by 2n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
Bit “0”
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Octal to Decimal
Decimal Octal
Binary Hexadecimal
Octal to Decimal
• Technique
– Multiply each bit by 8n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Decimal
• Technique
– Multiply each bit by 16n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
ABC16 => C x 160 = 12 x 1 = 12
B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Binary to Octal
Decimal Octal
Binary Hexadecimal
Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits
Example
10110101112 = ?8
1 011 010 111
1 3 2 7
10110101112 = 13278
Octal to Binary
Decimal Octal
Binary Hexadecimal
Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent
binary representation
Example
7058 = ?2
7 0 5
111 000 101
7058 = 1110001012
Binary to Hexadecimal
Decimal Octal
Binary Hexadecimal
Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Example
10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
Hexadecimal to Binary
Decimal Octal
Binary Hexadecimal
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2
1 0 A F
0001 0000 1010 1111
10AF16 = 00010000101011112
Octal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Octal to Hexadecimal
• Technique
– Use binary as an intermediary
Example
10768 = ?16
1 0 7 6
001 000 111 110
2 3 E
10768 = 23E16
Hexadecimal to Octal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Octal
• Technique
– Use binary as an intermediary
Example
1F0C16 = ?8
1 F 0 C
0001 1111 0000 1100
1 7 4 1 4
1F0C16 = 174148
2510 = 110012 = 318 = 1916
Base
Decimal Binary Octal Hexa-decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
Decimal Binary Octal Hexa-decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Decimal Binary Octal Hexa-decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17
Exercise – Convert ...
Decimal Binary Octal Hexa-decimal
33
1110101
703
1AF
Don’t use a calculator!
Decimal Binary Octal Hexa-decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Further Explanation
and Examples
Converting Base-2 to Base-10
(1 0 0 1 1)
2
OFF
OFF
ON
ON
ON
Exponent:
Calculation:16 0 0 2 1
+ + + + =
(19)10
• The Decimal Number System uses base 10.
It includes the digits {0, 1,2,…, 9}. The
weighted values for each position are:
Base
10^4 10^3 10^2 10^1 10^0 10^-1 10^-2 10^-3
10000 1000 100 10 1 0.1 0.01 0.001
left of the decimal point Right of decimal point
58
Binary System
• Most modern computer system using binary logic. The
computer represents values(0,1) using two voltage
levels (usually 0V for logic 0 and either +3.3 V or +5V
for logic 1).
• The Binary Number System uses base 2 includes only
the digits 0 and 1
Base
• The weighted values for each position are :
2^5 2^4 2^3 2^2 2^1 2^0 2^-1 2^-2
32 16 8 4 2 1 0.5 0.25
• Binary to Decimal: multiply each digit by its
weighted position, and add each of the weighted
values together or use expansion formdirectly.
• Example the binary value 1100 1010 represents :
• 1*2^7 + 1*2^6 + 0*2^5 + 0*2^4 + 1*2^3 + 0*2^2 +
1*2^1 + 0*2^0 =
• 1 * 128 + 1 * 64 + 0 * 32 + 0 * 16 + 1 * 8 + 0 * 4 + 1 *
2+0*1=
• 128 + 64 + 0 + 0 + 8 + 0 + 2 + 0 =202
• Example: convert the number 333 to binary.
Division Quotient Remainder Binary
333/2 166 1 1
166/2 83 0 01
83/2 41 1 101
41/2 20 1 1101
20/2 10 0 01101
10/2 5 0 001101
5/2 2 1 1001101
2/2 1 0 01001101
1/2 0 1 101001101
Octal System
Computer scientists are often looking for
shortcuts to do things
One of the ways in which we can represent
binary numbers is to use their octal
equivalents instead
This is especially helpful when we have to do
fairly complicated tasks using numbers
• The octal numbering system includes
eight base digits (0-7)
• After 7, the next placeholder to the
right begins with a “1”
• 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 ...
Octal Placeholders
Number: 2 4 1
“Sixty-
Fours”
“Eights
”
“Ones
”
Placeholder
Name:
Value: 64*2 8*4 1*1
Exponential
Expression: 82*2 81*4 80*1
Transform (44978)10 to Octal
Division Quotient Remainder Binary
• .
44978 / 8 5622 2 2
5622 / 8 702 6 62
702/8 87 6 662
87/8 10 7 7662
10/8 1 2 27662
1/8 0 1 127662
Numbers
Natural Numbers
Zero and any number obtained by repeatedly adding
one to it.
Examples: 100, 0, 45645, 32
Negative Numbers
A value less than 0, with a – sign
Examples: -24, -1, -45645, -32
2
Natural Numbers
642 is 600 + 40 + 2 in BASE 10
The base of a number determines the
number of digits and the value of digit
positions
5
Positional Notation
Continuing with our example…
642 in base 10 positional notation is:
6 x 102 = 6 x 100 = 600
+ 4 x 101 = 4 x 10 = 40
+ 2 x 10º = 2 x 1 = 2 = 642 in base 10
The power indicates
This number is in the position of
base 10 the number
6
Positional Notation
R is the base
of the number
As a formula:
dn * Rn-1 + dn-1 * Rn-2 + ... + d2 * R + d1
n is the number of d is the digit in the
digits in the number ith position
in the number
642 is 63 * 102 + 42 * 10 + 21
7
Positional Notation
What if 642 has the base of 13?
+ 6 x 132 = 6 x 169 = 1014
+ 4 x 131 = 4 x 13 = 52
+ 2 x 13º = 2 x 1 = 2
= 1068 in base 10
642 in base 13 is equivalent to 1068
in base 10
8
6
Binary
Decimal is base 10 and has 10 digits:
0,1,2,3,4,5,6,7,8,9
Binary is base 2 and has 2 digits:
0,1
For a number to exist in a given base, it can only contain the
digits in that base, which range from 0 up to (but not including)
the base.
9
Bases Higher than 10
How are digits in bases higher than 10
represented?
With distinct symbols for 10 and above.
Base 16 has 16 digits:
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, and F
10
Converting Octal to Decimal
What is the decimal equivalent of the octal
number 642?
6 x 82 = 6 x 64 = 384
+ 4 x 81 = 4 x 8 = 32
+ 2 x 8º = 2 x 1 = 2
= 418 in base 10
11
Converting Hexadecimal to
Decimal
What is the decimal equivalent of the
hexadecimal number DEF?
D x 162 = 13 x 256 = 3328
+ E x 161 = 14 x 16 = 224
+ F x 16º = 15 x 1 = 15
= 3567 in base 10
Remember, the digits in base 16 are
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Converting Binary to Decimal
What is the decimal equivalent of the binary
number 1101110?
1 x 26 = 1 x 64 = 64
+ 1 x 25 = 1 x 32 = 32
+ 0 x 24 = 0 x 16 =0
+ 1 x 23 = 1x8 =8
+ 1 x 22 = 1x4 =4
+ 1 x 21 = 1x2 =2
+ 0 x 2º = 0x1 =0
= 110 in base 10
13
Binary/Octal/Decimal
Binary to Octal
• Mark groups of three (from right)
• Convert each group
10101011 10 101 011
2 5 3
10101011 is 253 in base 8
17
Converting Binary to Hexadecimal
• Mark groups of four (from right)
• Convert each group
10101011 1010 1011
A B
10101011 is AB in base 16
18
Converting Binary to Octal
start
100011001010012
STEP ONE: Take the binary number
and from right to left, group all
placeholders in triplets. Add leading
zeros, if necessary:
010 001 100 101 001
0010 001 100 101 0012 = 214518
STEP TWO: Convert each triplet to its
single-digit octal equivalent. (HI NT:
For each triplet, the octal conversion
is the same as converting to a
decimal number):
010 001 100 101 001
2 1 4 5 1
Converting Octal to Binary
435208 = 1000111010100002
STEP ONE: Take each octal digit and
convert each digit to a binary triplet.
Keep leading zeros:
4 3 5 2 0
100 011
0 101 010
0 000
Hexadecimal System
• Sometimes, it is necessary to use a
numbering system that has more than ten
base digits
• One such numbering system, hexadecimal,
is useful on the Web
• Hexadecimal number, a Base-16 numbering
system, is used in specifying web colors
Hexadecimal Numbering
There are new symbols for the Base-16 equivalents
of the Base-10 numbers 10, 11, 12, 14 and 15.
Examine:
DEC 0 1 2 3 4 5 6 7
HEX 0 1 2 3 4 5 6 7
DEC 8 9 10 11 12 13 14 15
HEX 8 9 A B C D E F
Decimal Hexadecimal Octal Binary
0 0 0 0000
1 1 1 0001
2 2 2 0010
3 3 3 0011
4 4 4 0100
5 5 5 0101
6 6 6 0110
7 7 7 0111
8 8 10 1000
9 9 11 1001
Decimal Hexadecimal Octal Binary
10 A 12 1010
11 B 13 1011
12 C 14 1100
13 D 15 1101
14 E 16 1110
15 F 17 1111
• Binary to Hex Conversion
• Break the binary number into 4-bit groups
from the Left to the right.
• Convert the 4-bit binary number to its Hex
equivalent.
• For example, the binary value 101011111011
0010 will be written:
• 1010 1111 1011 0010=AFB2
• Hex to Binary Conversion
• Convert the Hex number to its 4-bit binary
equivalent.
• Combine the 4-bit groups by removing the
spaces.
• For example, the hex value AFC7 will be
written:
• AFC7=1010 1111 1110 0111
Decimal to Hex Conversion
• Repeated Division By 16
• Divide the decimal number by 16, and write the
remainder on the side as the least significant digit.
• This process is continued by dividing the quotient
by 16 and writing the remainder until the quotient
is 0.
• the remainders represent the hex equivalent of the
decimal number are written beginning at the least
significant digit (right) and each new digit is written
to the next more significant digit (the left) of the
previous digit.
Example convert 196710 to Hex
Division Quotient Remainder Hex Number
1967/16 122 15 F
122/16 7 10 AF
7/16 0 7 7AF
Then (1967)10 =(7AF)16
Decimal to Hexadecimal Conversion
Convert 83010 to its hexadecimal equivalent:
830 / 16 = 51 R14
51 / 16 = 3 R3 = E in Hex
3 / 16 = 0 R3
33E16
Hexadecimal to Decimal Conversion
Convert 3B4F16 to its decimal equivalent:
Hex Digits
3 B 4 F
x x x x
Positional Values
163 162 161 160
Products 12288 +2816 + 64 +15
15,18310
Binary to Hexadecimal Conversion
• The easiest method for converting binary to
hexadecimal is to use a substitution code
• Each hex number converts to 4 binary digits