1 Number Systems
1 Number Systems
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.
Why Binary System?
OFF
OFF
ON
ON
ON
Exponent:
Calculation:16 0 0 2 1
+ + + + =
(19)10
Number systems include decimal, binary, octal
and hexadecimal
32 16 8 4 2 1 0.5 0.25
1.3 Number Base Conversion
• 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
• Decimal to Binary
There are two methods, that may be used to convert
from integer number in decimal form to binaryform:
1-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.
• 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:
Decimal Octal
Binary Hexadecimal
2510 = 110012 = 318 = 1916
Base
Decimal Octal
Binary Hexadecimal
Weight
Base
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
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
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
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
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 Octal
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
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
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
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF
/ 230 =
Exercise – Free Space
• Determine the “free space” on all drives on a
machine in the lab
Free space
Drive Bytes GB
A:
C:
D:
E:
etc.
Review – multiplying powers
• For common bases, add powers
ab × ac = ab+c
A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Binary Addition (2 of 2)
• Two n-bit values
– Add individual bits
– Propagate carries
– E.g.,
1 1
10101 21
+ 11001 + 25
101110 46
Multiplication (1 of 3)
• Decimal (just for fun)
35
x 105
175
000
35
3675
Multiplication (2 of 3)
• Binary, two 1-bit values
A B A×B
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication (3 of 3)
• Binary, two n-bit values
– As with decimal values
– E.g., 1110
x 1011
1110
1110
0000
1110
10011010
Fractions
• Decimal to decimal (just for fun)
Natural Numbers
Zero and any number obtained by repeatedly adding
one to it.
Negative Numbers
A value less than 0, with a – sign
2
Numbers
Integers
A natural number, a negative number, zero
Rational Numbers
An integer or the quotient of two integers
3
Natural Numbers
5
Positional Notation
642 is 63 * 102 + 42 * 10 + 21
7
Positional Notation
8
6
Binary
What bases can these numbers be in? 122, 198, 178, G1A4
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
Arithmetic in Binary
Remember that there are only 2 digits in binary,
0 and 1
1 + 1 is 0 with a carry
Carry Values
111111
1010111
+1 0 0 1 0 1 1
10100010
14
Subtracting Binary Numbers
12
202
1010111
- 111011
0011100
15
Counting in Binary/Octal/Decimal
Converting Binary to Octal
17
Converting Binary to Hexadecimal
10101011 is AB in base 16
18
Binary Numbers and Computers
Low Voltage = 0
High Voltage = 1 all bits have 0 or 1
22
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
• Convert a hexadecimal number to a binary
number,
• simply divided the binary number into 4-bit
groups
• substitute the corresponding four bits in
binary for each hexadecimal digit in the
number.
• For example, convert ABCD to a binary value,
The binary equivalent is:
• ABCD= 1010 1011 1100 1101
• 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
• To convert from Hex to Decimal,
• multiply the value in each position by its hex
weight and
• add each value. use the expansion form
• AFB.2=10*163 +15*162 +11*16+2*16-1
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
0.062510 = .00012
Fraction Product with New fraction integer
Base
0.0625 8X0.0625 0.5000 .0
0.5 8X0.5 4. 0 .04
0.062510 = .048
0.062510 = .116
Convert (1967.0626)10 to B,O,H
Division Quotient Remainder Hex Number
1967/8 245 7 7
245/8 30 3 37
30/8 3 6 376
3/8 0 3 3637
(1967.0626)10= (3637.04)8
Binary Addition
+ 0 1
• 0+0=0
• 0+1=1
• 1+0=1
0 0 1
• 1 + 1 = 10
1 1 10
Multiply Binary numbers
* 0 1
0*0=0
0*1=0
1*0=0
0 0 0
1*1=1
1 0 1
– 1111 carry 1 1 1 (carry)
–111101 01101
1 0 1 1 1+
100111+ -------------
• 1100100 100100
Multiply 1011 and 1010
– 1 0 1 1
×1 0 1 0
---------------
0 0 0 0
1 0 1 1
0 0 0 0
+1 0 1 1
------------------
1 1 01 1 1 0
Multiply Example
1 1 0 1 1 1
1 1 1
1 1 0 1 1 1
1 1 0 1 1 1
1 1 0 1 1 1
------------------------------------
1 0 1 1 1 1 0 1 1
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.
Multiplication Algorithm
Convert (10101101)2 to its decimal equivalent:
Binary 1 0 1 0 1 1 0 1
Positional Values x x x x x x x x
27 26 25 24 23 22 21 20
Products 128 + 32 + 8 + 4 + 1
17310
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