1. Digital Logic Design (EEEg4302)
Chapter 2 : Number System
AASTU
Department of Electrical and
Computer Engineering
1
Milkias H.
2. Outline
Chapter 2 : Number System
• Decimal Numbers
• Binary Numbers
• Decimal to Binary Conversion and vice versa
• 1’s and 2’s compliment of binary number
• Signed Number
• Hexadecimal number
• Octal number
• Binary Coded Decimal (BCD) Number
2
3. Decimal Numbers
• In the decimal number system each of the ten digits 0 through 9 represents a certain quantity.
• The base(radix) of decimal numbers is 10. The position of each digit in a weight number
system is assigned a weight based on the base of the system.
• The column weights of decimal numbers are powers of ten that increase from right to left
beginning with
… … 102
101
100
• For fractional decimal numbers, the column weights are negative powers of ten that decrease
from left to right.
10−1
10−2
10−3
……
• Decimal numbers can be expressed as the sum of the products of each digit times the column
values for that digit.
Example:
123 → 1*102
+ 2*101
+ 3*100
45.367 → 4*101
+ 5*100
+ 3*10−1
+ 6*10−2
+ 7*10−3
3
4. Binary Numbers
• The binary number system is another way to represent quantities.
• It have two digits: 0 and 1. so it is base 2 system.
• The position of a 1 and 0 in a binary number indicates weight.
• The weight of a binary number is based on powers of two.
24
23
22
21
20
• For fractional binary number the weight are negative power of two that decrease from left two
right.
2−12−22−32−42−5
4
6. Decimal to Binary Numbers
• For Non Fractional Number
Repeated Division by two methods.
(160)10 = (10100000)2
• For Fractional Number
Repeated multiplication by two.
(0.188)10 = (0.00110)2 → for five significant digits
6
7. Binary to Decimal Conversion
• The decimal value of any binary number can be found by adding the weights of
all bits that are 1 and discarding the weight of all bits that are 0.
• We multiply each binary digits by its weighted position and add each of the
weighted value together.
7
8. Binary to Decimal Conversion
• Any numbering system can be summarized by the following relationship:
8
9. Binary to Decimal Conversion
• Example
9
(1010)2 = (10)10 (0.1011)2 = (0.6875)10
10. Binary to Decimal Conversion
Exercise
• Convert the following decimal to binary format:
65
25.4
• Convert the following binary to decimal format:
101011
1010.01
10
11. 1’s and 2’s Compliment of Binary Number
o 1’s compliment representation:
• Is just the inverse of a binary number.
• To form 1’s compliment invert very bit of the number.
• 1’s compliment of 1001 is 0110.
o 2’s compliment representation:
• Found by adding 1 to LSB of the 1’s compliment.
• 2’s compliment of 1001 is 0110 + 1, which is 0111.
11
12. Signed Number
• Digital systems, such as computer must handle both positive and negative numbers.
• A signed binary number consists of both sign and magnitude information.
• There are three forms in which signed numbers can be represented in binary:
I. Sign-magnitude form (least used)
II. 1’s complement form
III. 2’s complement form (most important)
• N.B: The left most bit (MSB) in all forms of a signed number is the sign bit, which tells you
whether the number is positive or negative.
Positive number → 0 for sign bit
Negative number → 1 for sign bit
12
13. Signed Number
I. Sign-magnitude form
• When a signed binary number is represented in sign-magnitude form, the left most bit is the
sign bit and the remaining bits are magnitude bits in true (uncomplemented form).
• Example: using sign-magnitude form (+9) expressed as 8 bit signed binary
And (-9) as
• Notice that the only difference between (+9) and (-9) is the sign bit.
13
1 0 1 0 1 0 1 0
Sign bit Magnitude bits
0 0 0 0 1 0 0 1
1 0 0 0 1 0 0 1
14. Signed Number
II. 1’s complement form
• Positive numbers in 1’s complement form are represented the same way as sign-magnitude
numbers.
• Negative numbers are the 1’s complements of the corresponding positive numbers.
• Example: using 1’s complement form (+9) expressed as 8 bit signed binary
And (-9) as
14
0 0 0 0 1 0 0 1
1 1 1 1 0 1 1 0
1’s complement
15. Signed Number
III. 2’s complement form
• Positive numbers in 2’s complement form are represented the same way as sign-magnitude
and 1’s complement forms.
• Negative numbers are the 2’s complement of the corresponding positive numbers.
• Example: using 2’s complement form (+9) expressed as 8 bit signed binary
And (-9) as
• An easy way to read a signed number that uses this notation is to assign the sign bit a column
weight of -128 (for an 8-bit number). Then add the column weight for the 1’s.
15
0 0 0 0 1 0 0 1
1 1 1 1 0 1 1 1
2’s complement
16. Signed Number
• Exercise: Express the decimal number (-20) as an 8 bit number in the (i) Sign-magnitude
(ii) 1’s complement and (iii) 2’s complement forms.
First, find 8 bit binary conversion of (+20)
(i) Sign-magnitude
o change the sign bit to one
(ii) 1’s complement
o 1’s complement of (+20)
(iii) 2’s complement forms.
o 2’s complement of (+20)
16
0 0 0 1 0 1 0 0
1 0 0 1 0 1 0 0
1 1 1 0 1 0 1 1
1 1 1 0 1 1 0 0
17. Signed Number
• Why 2’s complement form is preferred for representing signed integer numbers?
o Because its easier to convert back to decimal.(1’s complement requires adding 1 to summation
of weight)
o And there are two possible representations of zeros in 1’s complement form which are
[00000000] and [11111111].
Range Of Signed Integer Numbers That Can Be Represented
o The formula for finding the number of different combinations of n-bit is
Total combination = 2𝑛
o For 2’s complement signed numbers, the range of values for n-bit numbers is
Range = - (2𝑛−1) to +(2𝑛−1 - 1)
17
18. Signed Number
Arithmetic Operations With Signed Numbers
1. ADDITION:
• The addition of two signed numbers with negative numbers represented in signed 2’s
complement form is obtained from the addition of the two numbers including their sign bits.
• A carry out of the sign bit position is discarded.
Example: +6 00000110 -6 11111010
+13 00001101 +13 00001101
+19 00010011 +7 00000111
: +6 00000110 -6 11111010
-13 11110011 -13 11110011
-7 11111001 -19 11101101
18
1 Discard carry
1 Discard carry
addend
augend
sum
19. Signed Number
Arithmetic Operations With Signed Numbers
1. ADDITION:
• 0verflow condition : when two numbers are added and the number of bits to represent the
sum exceeds the number of bits in the two numbers.
• An over flow results as indicated by an incorrect sign bit.
• Occurs only when both numbers are positive or when both numbers are negative.
19
20. Signed Number
Arithmetic Operations With Signed Numbers
2. SUBTRACTION:
• Subtraction is addition with the sign of the subtrahend changed. As demonstrated by the
following relationship
(±A) - (+B) = (±A) + (-B)
(±A) - (-B) = (±A) + (+B)
• Take the 2’s complement of the subtrahend (including the sign bit) and add it to the minuend
(including the sign bit). A carry out of the sign bit position is discard.
Example : subtracting +6 (the subtrahend) from +9(minuend) is equivalent to adding (-6) to (+9).
(9) - (6) = 3 = (9) + (-6)
20
difference
minuend
subtrahend
-6 11111010
+9 00001001
+3 00000011
1 Discard carry
21. Signed Number
Arithmetic Operations With Signed Numbers
3. MULTIPLICATION:
• The multiplication operation in most computers is accomplished using addition.
• Direct addition and partial products are two basic methods for performing multiplication using addition.
• In direct addition method, you add the multiplicand a number of times equal to the multiplier.
• The partial product method is the more common one. The multiplicand is multiplied by each multiplier digit
beginning with the least significant digit.
Example 1. multiply the signed binary numbers 01001101 (multiplicand) and 00000100 (multiplier) using direct
addition method.
Solution since both numbers are positive, they are in true form and the product will positive .
the decimal value of the multiplier is 4, so the multiplicand is added to it self four time as follows
01001101 1st time
+01001101 2nd time
10011010 partial sum
+01001101 3rd time
11100111 partial sum
+01001101 4th time
100110100 product
21
22. Signed Number
Arithmetic Operations With Signed Numbers
3. MULTIPLICATION:
Example 2. Multiply the signed binary number 01010011 (multiplicand) and 11000101
(multiplayer) using partial product method.
Step 1. The sign bits are different, the product will be negative (1).
Step 2. Take the 2’s complement of the multiplier to put it in true form.
11000101 00111011
22
Step 3. the multiplication proceed as follows. Notice that only
the magnitude bits are used in this step.
Step 4. since the sign of product is 1 as determined in step 1,
take the 2’s compliment of the product.
1001100100001 0110011011111
Attach the sign bit 1 0110011011111
23. Signed Number
Arithmetic Operations With Signed Numbers
4. DIVISION:
• The division operation computers is accomplished using subtraction.
• Since subtraction is done with an adder, division can be accomplished with an adder.
𝑑𝑖𝑣𝑖𝑑𝑒𝑛𝑑
𝑑𝑖𝑣𝑖𝑠𝑜𝑟
= 𝑞𝑢𝑜𝑡𝑖𝑒𝑛𝑡
Example
Divide 01100100 by 00011001
Solution. Step 1, the sign of both numbers are positive .
Step 2. subtract the divisor from dividend using 2’s compliment addition .
01100100
+11100111
01001011
Add 1 to quotient( quotient is initially zero): 00000000 + 00000001 = 00000001
23
dividend
2’s compliment of divisor
Positive first partial remainder
24. Signed Number
Arithmetic Operations With Signed Numbers
4. DIVISION:
Step 3. subtract the divisor from the 1st partial remainder using 2’s compliment addition .
01001011
+11100111
00110010
Add 1 to quotient : 00000010
Step 4. subtract the divisor from the 2nd partial remainder using 2’s complement addition
00110010
+11100111
00011001
Add 1 to quotient : 00000011
Step 5. subtract the divisor from 3rd partial remainder using 2’s complement addition
24
1st partial remainders
2’s complement of divisor
Positive 2nd partial remainder
2nd partial remainders
2’s complement of divisor
Positive 3rd partial remainder
25. Signed Number
Arithmetic Operations With Signed Numbers
4. DIVISION:
Step 5. subtract the divisor from 3rd partial remainder using 2’s complement addition
00011001
+11100111
00000000
Add 1 to quotient : 00000100 (final quotient).
25
3rd partial remainder
2’s complement of divisor
zero remainder
26. Hexadecimal Number
• The hexadecimal number system has sixteen characters; Consists of digits 0-9
and letters A-F.
• It is used primarily as a compact way of displaying or writing binary numbers.
• Is widely used in computer and microprocessor applications.
• Has a base of sixteen.
• Large binary number can easily be converted to hexadecimal by grouping bits
4 at a time and writing the equivalent hexadecimal character.
26
27. Hexadecimal Number
27
Counting in hexadecimal
• Once you get to F, simply start over with other column and continue.
• With two hexadecimal digits, you can count up to (FF) which is 255 in decimal.
• The maximum three digit is (FFF) or decimal 4095.
28. Hexadecimal Number
Binary to Hexadecimal conversion
• Converting a binary number to hexadecimal is straight forward procedure.
Simply break the binary number in to 4 bit group with the equivalent
hexadecimal symbol.
• Example: convert the following binary number to hexadecimal:
a) 1100101001010111 = CA5716
b) 1010000111100011 = A1E316
28
29. Hexadecimal Number
Hexadecimal to Binary conversion
• To convert from hexadecimal number to a binary number reverse the process
and replace each hexadecimal symbol with the appropriate four bits.
• Example: Determine the binary number for the following hexadecimal number:
(a) 10A416
0001000010100100
(b) AF6C16
1010111101101100
29
30. Hexadecimal Number
Hexadecimal to Decimal conversion
• To find the decimal equivalent of hexadecimal number is first convert the hexadecimal
number to binary and then convert from binary to decimal
• Example: 2D
00101101 00101101 20
+ 22
+ 23
+ 25
=4510
• 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 structure
• Example 2D = (2x16) + (Dx1)
= 32+ 13
=4510
30
163 162 161 160
4096 256 16 1
31. Hexadecimal Number
Decimal to Hexadecimal conversion
• Repeated division of a decimal number by 16 will produce the equivalent
hexadecimal number, formed by remainders of the divisions.
• The first remainder produce is least significant digit (LSD).
• Note that when a quotient has a fraction part, the fraction part is multiplied by the
divisor to get the remainder.
• Example : convert the decimal number 650 to hexadecimal by repeated division by 16.
31
32. Octal Number
• Like hexadecimal number system the octal number system provides a convenient way
to express binary numbers and codes.
• However it 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 is composed of eight digits, which are; 0 1 2 3 4 5 6 7
32
33. Octal Number
Octal to Decimal conversion
• Octal is also a weight number system. The column weights are powers of 8, which
increase from right to left.
• Example: Express (3702)8 in decimal.
3 7 0 2
83 82 81 80
512 64 8 1
3(512) + 7(64) + 0(8) + 2(1) = (1986)10
33
34. Octal Number
Decimal to Octal Conversion
• A method of converting a decimal number to an octal number is the repeated
division-by-8 methods.
• Each successive division by 8 yield a remainder that become a digit in the equivalent
octal number .
• The first remainder generated is the least significant digit (LSD).
• Example: convert decimal number (359)10 to octal
34
35. Octal Number
Binary to Octal Conversion
• Binary number can easily be converted to octal by grouping bits 3 at a time
and writing the equivalent octal character for each group.
• Example: Express (100110010010)2 in octal.
100 110 010 010
4 6 2 2 = (4622)8
35
36. Octal Number
Octal to Binary Conversion
• Because each octal digit can be represented by a 3-bit binary number, it is
very easy to convert from octal to binary.
• Each octal digit is represented by three bits.
• Example: Convert (613)8 in binary.
6 1 3
110 001 011 = (110001011)2
36
37. Binary Coded Decimal - BCD
• Binary coded decimal is a way to express each of the decimal digits with a
binary code.
• There are 10 groups in the BCD system.
• BCD is a weighted code that is commonly used in digital systems when it is
necessary to show decimal numbers such as in clock displays.
• BCD represents each decimal digit with a 4-bit code.
• Notice that the codes 1010 through 1111 are not used in BCD.
• For 4 bit BCD number, the column weights are 8 4 2 1 (23222120).
• The ease of conversion between 8421 code numbers and familiar decimal
numbers is the main advantage of the code.
• To express any decimal number in BCD, simply replace each decimal digit with
the appropriate 4 bit code.
37
39. Binary Coded Decimal - BCD
Example : convert decimal 170 to BCD
1 7 0
0001 0111 0000
To determine a decimal number from a BCD number, start at the right most bit
and break the code in to groups of four bits. Then write the decimal digit
represented by each 4 bit group.
Example : convert the BCD number 001101010001 to decimal
0011 0101 0001
3 5 1 (351)10
39
40. Assignment 1:
• Read and prepare a short note and presentation on Digital
codes (Gray code and ASCII) [text book: page 87- ]
DUE DATE : April 28, 2021
40