1 - Number Systems
1 - Number Systems
1 - 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?
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
Decimal Octal
Binary Hexadecimal
Decimal Octal
Binary Hexadecimal
Weight
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
Decimal Octal
Binary Hexadecimal
Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits
Example
10110101112 = ?8
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
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
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
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
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
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
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:
Negative Numbers
A value less than 0, with a – sign
2
Natural Numbers
5
Positional Notation
642 is 63 * 102 + 42 * 10 + 21
7
Positional Notation
8
6
Binary
9
Bases Higher than 10
10
Converting Octal to Decimal
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?
13
Binary/Octal/Decimal
Binary to Octal
17
Converting Binary to Hexadecimal
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:
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
1967/16 122 15 F
122/16 7 10 AF
7/16 0 7 7AF
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