2 Lecture Two
2 Lecture Two
By
❑ Example: Express the decimal number 480.52 as a sum of the values of each
digit.
❑ Solution:
480.52 = (4 x 10 2 ) + (8 x 10 1 ) + (0 x 10 0 ) + (5 x 10 -1 ) +(2 x 10 -2 )
= (4 x 100 ) + (8 x 10 ) + (0 x 1 ) + (5 x 0.1 ) +(2 x 0.01 )
= 400 + 80 + 0 + 0.5 + 0.02
Binary Numbers
❑ For digital systems, the binary number system is used.
❑ It has only two digits (bits) 0 and 1, hence, It is a base-two system.
❑ The column weights of binary numbers are powers of two that increase from
right to left beginning with 2 0 =1.
252423222120
❑ For fractional binary numbers, the column weights are negative powers of two
that decrease from left to right
2 n-1 ……2 2 2 1 2 0. 2 -1 2 -2 2 -3 2 -4 …… 2 -n
❑ Four bits are required to count from zero to 15. In general, with n bits you can
count up to a number equal to 2n - 1.
Decimal-to-Binary Conversion.
There are two methods for converting whole numbers from decimal to
binary.
The First Method: Sum-of-Weights
❑ Determine the set of binary weights whose sum is equal to the decimal
number to find the binary number that is equivalent to a given decimal
number.
❑ The decimal number 9, for example, can be expressed as the sum of
binary weights as follows: 9 = 8 + 1 or 9 = 23 + 20 =1001
❑ Example: Convert the following decimal numbers to binary:
12 , 25 ,58 , 82
❑ Solution:
12 = 8 +4 = 23 + 22 -----------------------------------1100
25 = 16 + 8 + 1 = 24 + 23 + 20------------------------11001
58 = 32 + 16 + 8 +2 = 25 + 24 + 23 + 21 ------------111010
82 = 64 + 16 + 2 = 26 + 24 + 21 ----------------------1010010
Decimal-to-Binary Conversion.
Converting Decimal Fractions to Binary use First Method
❑ The sum-of-weights method can be applied to fractional decimal numbers,
❑ Solution:
= 0. 00110
Binary-to-Decimal Conversion
❑ The decimal equivalent of any binary number can be determined adding the
weights of all bits that are 1 and discarding the weights of all bits that are 0.
❑ Solution:
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
1 0 0 1 0 1. 0 1
32 + 4 + 1. + 0.25
= 37.25
Binary Arithmetic
❑ Binary arithmetic is essential in all types of digital systems. To understand
these systems, you must know the basics of binary Addition, Subtraction,
Multiplication, and 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
❑ Notice that the first three rules result in a single bit and in the fourth rule
the addition of two 1s yields a binary two (10). When binary numbers are
added, the last condition creates a sum of 0 in a given column and a carry
of 1 over to the next column to the left.
Binary Arithmetic
❑ Example: Add 11 + 1
❑ Solution:
❑ 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 basic rules
just listed must be applied
Binary Arithmetic
❑ Example: Subtract 011 from 101
❑ Solution:
0×0=0
0×1=0
1×0=0
1×1=1
Method 1:
❑ Adding 1 to the LSB of the 1’s complement.
2’s complement = (1’s complement) + 1
Method 2:
❑ take the 1’s complements of all the bits to the left of the least significant 1.
Complements of Binary Numbers
❑ Example: Find the 2’s complement of 10111000
❑ Solution:
Binary Subtraction using 2’s complement
❑ Instead of subtracting a number, we can add its 2’s complement, and
discard the last carry.
❑ With two hexadecimal digits, you can count up to FF. To count beyond FF,
three hexadecimal digital are needed where the maximum 3-digit
hexadecimal number is FFF
Binary-to-Hexadecimal Conversion
❑ To convert a binary number to a hexadecimal, break the binary number into 4-
bit groups. Then, starting at the right-most bit and replace each 4-bit group with
equivalent hexadecimal symbol.
❑ Example: Convert the following binary numbers to hexadecimal:
a) 1100101001010111 b)11111100010110100
❑ Solution:
❑ Note: two zeros have been added in (b) to complete a 4-bit group at the left.
Hexadecimal to Binary Conversion
❑ To convert from a hexadecimal number to binary number, replace each
hexadecimal symbol with the corresponding four bits.
❑ Example: Determine the binary numbers for the following hexadecimal
numbers:
a) 10A4 b)CF8E c)9DB5
❑ Solution:
c)
Hexadecimal-to-Decimal-Conversion
❑ There are two methods for converting whole numbers from Hexadecimal to
Decimal.
Method1:
❑ Convert the hexadecimal number to binary number and then convert from
binary to decimal.
❑ Example: Convert the hexadecimal numbers to decimal.
(a)1C b) A85)
❑ Solution:
Hexadecimal-to-Decimal-Conversion
Method 2:
❑ Multiply the decimal value of each hexadecimal digit by its weight and then
take the sum of these product.
❑ The weights of a hexadecimal number are increasing powers of 16 from right
to left
❑ The octal number system provides a convenient way to express binary numbers
and codes.
❑ The octal number system is used less frequently than hexadecimal in
conjunction with computers and microprocessors to express binary quantities
for input and output purposes.
❑ The octal number system consists of eight digits, which are 0,1,2,3,4,5,6,7
❑ To count above 7, begin another column and start over: 10, 11, 12, 13, 14, 15,
16, 17, 20, 21, …
❑ Sometimes, you may see an “o” or a “Q” following an octal number
Octal-to-Decimal Conversion
Octal 0 1 2 3 4 5 6 7
binary 000 001 010 011 100 101 110 111
❑ To convert an octal number to a binary number, replace each octal digit with
appropriate three bits.
❑ Example: Convert 7526 to binary
❑ Solution:
7 5 2 6
111 101 001 110
7527 = 111101001110
Binary-to-Octal Conversion
❑ Solution:
Octal Subtraction
❑ The subtraction of octal numbers follows the same rules as the subtraction of
numbers in any other number system.
❑ The only variation is in borrowed number. In the decimal system, you borrow a
group of 10. In the binary system, you borrow a group of 2. In the octal system
you borrow a group of 8.
❑ Example: subtract the following octal numbers:
a) 1066 - 776 b) 5142 - 2546
❑ Solution: