Week 7
Week 7
Week 7
Bits, Bytes
25 24 23 22 21 20
32 16 8 4 2 1
1 0 1 0 1 0
The Decimal Number System
(con’t)
• The decimal number system is also known
as base 10.
• The values of the positions are calculated
by taking 10 to some power.
• Why is the base 10 for decimal numbers?
– Because we use 10 digits, the digits 0 through
9.
Converting From Decimal to Binary
Practice conversions:
Decimal Binary
59
82
175
The Decimal Number System
• The decimal number system is a positional
number system.
• Example:
5 6 2 1 1 X 100 = 1
103 102 101 100 2 X 101 = 20
6 X 102 = 600
5 X 103 = 5000
The Binary Number System
• The binary number system is also known
as base 2. The values of the positions are
calculated by taking 2 to some power.
• Why is the base 2 for binary numbers?
– Because we use 2 digits, the digits 0 and 1.
The Binary Number System
(con’t)
• The binary number system is also a
positional numbering system.
• Instead of using ten digits, 0 - 9, the
binary system uses only two digits, 0
and 1.
• Example of a binary number and the
values of the positions:
1 0 0 1 1 0 1
26 25 24 23 22 21 20
Converting from Binary to
Decimal
1 0 0 1 1 0 1 1 X 20 = 1
26 25 24 23 22 21 20 0 X 21 = 0
1 X 22 = 4
20 = 1 24 = 16 1 X 23 = 8
21 = 2 25 = 32 0 X 24 = 0
22 = 4 26 = 64 0 X 25 = 0
23 = 8 1 X 26 = 64
7710
Another Example
– Example: Convert the binary whole number
1101101 to decimal.
Solution: Weight: 26 25 24 23 22 21 20
Binary number: 1 1 0 1 1 0 1
1101101 = 26 + 25 + 23 + 22 + 20
= 64 + 32 + 8 + 4 + 1 = 109
Fractional binary number
– Example: Convert the fractional binary
number 0.1011 to decimal.
Solution: Weight:0 2-1 2-2 2-3 2-4
Binary number: 0 . 1 0 1 1
0.1011 = 2-1 + 2-3 + 2-4
= 0.5 + 0.125 +0.0625 = 0.6875
Binary Arithmetic
• Binary Addition
• Binary Subtraction
• Binary Multiplication
• Binary Division
Binary Addition
• The four basic rules for adding binary digits
(bits) are as follows:
0+0=0 Sum of 0 with a carry of 0
0+1=1 Sum of 1 with a carry of 0
1+0=1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1
Binary Addition (contd.)
• When there is a carry of 1, you have a situation in
which three bits are being added ( a bit in each of
the two numbers and a carry bit).
• 1 + 0 + 0 =01 Sum of 1 with a carry of 0
• 1 + 1 + 0 =10 Sum of 0 with a carry of 1
• 1 + 0 + 1 =10 Sum of 1 with a carry of 1
• 1 + 1 + 1 =11 Sum of 1 with a carry of 1
Binary Addition (contd.)
• Example: Add the following binary numbers.
11 + 11
Solution : 1 1
+11
110
Binary Subtraction
• The four basic rules for subtracting binary digits (bits) are as
follows:
0-0=0
1-1=0
1-0=1
10 - 1 = 0 0 - 1 with a borrow of 1
• When subtracting numbers, you sometimes have to borrow
from the next column to the left.
• A borrow is required in binary only when you try to
subtract a 1 from a 0. In this case, when a 1 is borrowed
from the next column to the left, a 10 is created in the
column being subtracted and the last of the four rules must
be applied.
Binary Subtraction (contd.)
• Example: Perform the following binary
subtractions. 11 - 01
Solution : 1 1
-01
10
Binary Multiplication
• The four basic rules for multiplying binary digits (bits) are
as follows:
0x0=0
0x1=0
1x0=0
1x1=1
• Multiplication is performed with binary numbers in the
same manner as with decimal numbers.
• It involves forming partial products, shifting each
successive partial product left one place, and then adding all
the partial products.
Binary Multiplication (contd.)
• Example: Perform the following binary
multiplication. 11 x 01
Solution : 1 1
x11
11
+ 11 .
1001
Binary Division
• Binary division follows the same procedure
as division in decimal.
• Example : Perform the following binary
division: 110 / 11
Solution: 10
11 110
11
000
Converting from Binary to
Decimal
• Practice conversions:
• Binary Decimal
• 11101
• 1010101
• 100111
Working with Large Numbers
• 0101000010100111 = ?
• Octal
base = 8
8 symbols (0,1,2,3,4,5,6,7)
• Hexadecimal
base = 16
16 symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
The Hexadecimal Number
System
• The hexadecimal number system is also
known as base 16. The values of the
positions are calculated by taking 16 to
some power.
• Why is the base 16 for hexadecimal
numbers ?
– Because we use 16 symbols, the digits
0 through 9 and the letters A through F.
Binary-to-Hexadecimal Conversion
• Break the binary number into 4-bit groups,
starting at the right-most bit and replace
each 4-bit group with the equivalent
hexadecimal symbol.
29
Example
• Convert the following binary number to
hexadecimal:
1100101001010111
Solution: 1100101001010111
C A 5 7 CA5716
30
Hexadecimal to Binary Conversion
• To convert from a hexadecimal number to a
binary number, replace each hexadecimal
symbol with the appropriate four bits.
31
Example
• Determine the binary numbers for the
following hexadecimal number:
10A416
Solution: 1 0 A 4
32
Hexadecimal to Decimal Conversion
• One way to find the decimal equivalent of a
hexadecimal number is to first convert the
hexadecimal number to binary and then
convert from binary to decimal.
33
Example
• Convert the following hexadecimal numbers
to decimal. 1C16
Solution: 1 C
0001 1100 24 + 23 + 22 =16 + 8 + 4 = 2810
34
Hexadecimal to Decimal Conversion
(contd.)
• Another way to convert a hexadecimal number to
its decimal equivalent is to multiply the decimal
value of each hexadecimal digit by its weight and
then take the sum of these products. The weight of
a hexadecimal number are increasing powers of 16
(from right to left). For a 4-digit hexadecimal
number, the weights are: 163 162 161 160
4096 256 16 1
35
Example
• Convert the following hexadecimal numbers
to decimal. E516
36
Decimal-to-Hexadecimal Conversion
• Repeated division of a decimal number by 16
will produce the equivalent hexadecimal
number, formed by the remainders of the
divisions.
• The first remainder produced is the least
significant digit (LSD).
37
Hexadecimal Addition
• Addition can be done directly with
hexadecimal numbers by remembering that
the hexadecimal digits 0 through 9 are
equivalent to decimal digits 0 through 9 and
that hexadecimal digits A through F are
equivalent to decimal numbers 10 through
15.
38
Example
• Add the following hexadecimal number.
2316 +1616
Solution: 2316
+ 1616
3916
39
The Hexadecimal Number System
(cont.)
Binary Decimal Hexadecimal Binary Decimal Hexadecimal
0 0 0 1010 10 A
1 1 1 1011 11 B
10 2 2 1100 12 C
11 3 3 1101 13 D
100 4 4 1110 14 E
101 5 5 1111 15 F
110 6 6
111 7 7
1000 8 8
1001 9 9
The Hexadecimal Number
System
• Example of a hexadecimal number and
the values of the positions:
3 C 8 B 0 5 1
166 165 164 163 162 161 160
Octal Numbers
• The octal number system is composed of
eight digits, which are:
–0,1,2,3,4,5,6,7
• To count above 7:
– 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 20 , 21
42
Octal-to-Decimal Conversion
• The octal number system has a base of eight,
each successive digit position is an increasing
power of eight, beginning in the right-most
column with 80.
• The evaluation of an octal number in terms
of its decimal equivalent is accomplished by
multiplying each digit by its weight and
summing the products.
43
Octal-to-Decimal Conversion
(contd.)
• Example: Convert octal number 23748 to
decimal number.
Weight : 83 82 81 80
Octal number : 2 3 7 4
23748 = ( 2 x 83) + ( 3 x 82) + ( 7 x 81) + ( 4 x 80)
= ( 2 x 512) + ( 3 x 64) + ( 7 x 8) + ( 4 x 1)
= 1024 + 192 + 56 + 4
= 127610
44
Octal-to-Binary Conversion
• Replace each octal digit by a 3-bit binary
number.
• Example: Convert the following octal
numbers to binary: 138
Solution: 1 3
001 011
45
Binary-to-Octal Conversion
• Conversion of a binary number to an octal
number is the reverse of the octal-to-binary
conversion.
• The procedure is as follows:
– Start with the right-most group of three bits and
moving from right to left, convert each 3-bit
group to the equivalent octal digit.
– If there are not three bits available for the left-
most group, add either one or two zeros to make
a complete group.
46
Example
• Convert the following binary number to
octal: 110101
Solution: 110101
6 5 = 658
47
Example of Equivalent
Numbers
• Binary: 111111000000101000110
Octal: 07700506
• Decimal: 2064710
• Hexadecimal: 0x1F8146