DLD Lab4 Stmu
DLD Lab4 Stmu
DLD Lab4 Stmu
Lab Title:
Number System conversion and
Compliment Arithmetic
DEPARTMENT OF COMPUTING
Experiment No 4
There are four important number systems which you should become familiar with. These are
decimal, binary, octal and hexadecimal. The decimal system, which is the one you are most
familiar with, utilizes ten symbols to represent each digit. These are 0, 1, 2, 3, 4, 5, 6, 7, 8 and
9. This system is referred to as base 10, or radix 10 system. Similarly, the binary system is base
2, octal is base 8, and hexadecimal is base 16.
33
4.2.1.1 Decimal Number System
In the decimal number system, the numbers are represented with base 10. The way of denoting
the decimal numbers with base 10 is also termed as decimal notation. This number system is
widely used in computer applications. It is also called the base-10 number system which
consists of 10 digits, such as, 0,1,2,3,4,5,6,7,8,9. Each digit in the decimal system has a position
and every digit is ten times more significant than the previous digit. Suppose, 25 is a decimal
number, then 2 is ten times more than 5. Some examples of decimal numbers are:
The binary number system is a base 2 system with only two digits: 0 and 1. A binary number
such as “11010” is expressed with a string of 1s and 0s. The decimal equivalent of binary
number can be found by expanding the number into a power series with base of 2.
To avoid writing down long binary words, it is often easier to use larger base systems. Two
commonly-used systems are octal and hexadecimal. The octal number system is base eight, i.e.,
values can be represented using an 8-symbol dictionary: 0-7 to convert from binary to octal,
binary numbers are grouped on 3-bitswords.
The hexadecimal number system (HEX) is a base 16 notation. It is the most popular large-base
system for representing binary numbers. Each symbol represents 4-bits (1 nibble), that can take
one of 16 different values: the values 0-9 are represented by the digits 0-9, and the values 10-
15 are represented by the capital letters A-F respectively. Conversions are performed as with
the other number systems.
• Decimal to Base-N
• Base-N to Decimal
34
4.2.1.5.1 Base-N to Decimal
Convert from source base to decimal (base 10) by multiplying each digit with the base raised
to the power of the digit number (starting from right digit number 0).
For Example
Convert from decimal to destination base by divide the decimal with the base until the quotient
is 0 and calculate the remainder each time. The destination base digits are the calculated
remainders.
For Example
14/2 = 7 remainder 0
7/2 = 3 remainder 1
3/2 = 1 remainder 1
(29)10 = (11101)2
22 / 2 = 11 remainder 0 (LSB)
11 / 2 = 5 remainder 1
35
5 / 2 = 2 remainder 1
2 / 2 = 1 remainder 0
1 / 2 = 0 remainder 1 (MSB)
0.25×2=0+0.5
0.5×2=1+0
(22.25)10 = (10110.01)2
The BCD system uses four binary bits to represent each decimal digit. It is a convenient code
because it allows ready conversion from base ten to a code that a machine can understand;
however, it is wasteful of bits. A 4-bit binary number could represent the numbers 0 to 15, but
in BCD it represents only the quantities 0 through 9. The binary representations of the numbers
10 through 15 are not used in BCD and are invalid.
Complements are used in digital computers for simplifying the subtraction operation. There are
two types of complements for each base-r system.
36
• r’s complement
• (r-1)’s complement
When the value of the base is substituted the two types receive.
Subtraction of two +ve number (M-N) both of base r may be done as follows: Add the minuend
M to the r’s complement of the subtrahend N
If an end carry does not occur, take the r’s complement of the number obtained in step 1 and
place a –ve sign in front of it.
For Example:
M = 1010100, N = 1000100
M =1010100
Sum = 0010000
Subtraction of two +ve number (M-N) both of base r may be done as follows:
If an end carry does not occur, take the (r-1)’s complement of the number obtained in step 1
and place a –ve sign in front of it.
For Example:
M = 1010100
Sum = 10001111
The 7-segment display, also written as “seven segment display”, consists of seven LEDs (hence
its name) arranged in a rectangular fashion as shown. Each of the seven LEDs is called a
segment because when illuminated the segment forms part of a numerical digit (both Decimal
and Hex) to be displayed. An additional 8th LED is sometimes used within the same package
thus allowing the indication of a decimal point, (DP) when two or more 7-segment displays are
connected together to display numbers greater than ten.
The displays common pin is generally used to identify which type of 7-segment display it is.
As each LED has two connecting pins, one called the “Anode” and the other called the
“Cathode”, there are therefore two types of LED 7-segment display called: Common Cathode
(CC) and Common Anode (CA).
The difference between the two displays, as their name suggests, is that the common cathode
has all the cathodes of the 7-segments connected directly together and the common anode has
all the anodes of the 7-segments connected together and is illuminated as follows.
38
Figure 2: CA/CC circuitry
39
1) Begin by constructing the circuit shown in Figure 3. After wiring the circuit, connect power
and test each switch to see that it lights an LED.
2) Before applying power, check that you have connected a 330Ω current-limiting resistor
between each output of the decoder and the input to the MAN72. Connect the Lamp test,
BI/RBO, and RBI inputs through a 1.0 kΩ resistor to +5.0 V. This is a pull-up resistor, used to
assure a solid logic HIGH is present at these inputs.
3) When you have completed the wiring, apply power, and test the circuit by setting each switch
combination listed in Table 2.4 of the report. The last six codes are invalid BCD codes;
however, you can set the switch combinations in binary and observe the display. It will show a
unique display for each of the invalid codes. Complete the table by showing the appearance of
the seven-segment display in the output column.
01001100
304
E6
57
57.35
40
4.3.2 Task-2: Complement and Subtraction
Perform following subtraction using 2’s complement arithmetic covert the answer from
binary to decimal and cross check with decimal answer.
a) 42-29
b) 53-37
2) Don’t turn on power supply unless until you are sure your circuit is complete in all
aspects.
3) Verify your circuit and show it to your instructor before measuring/displaying the output
values.
4) Turn on power supply and fill the Table 4 using different combinations of input
switches.
41
Shown the filled table to your instructor.
Table 4: Output
Output
BCD Hex Seven-segment
Number Number Display
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
42
Lab Exercise and Summary
43
Student’s Signature: ________________ Date: ________________
44
Evaluation Criteria
Method of Evaluation: Viva, File submitted on LMS.
Assignment All tasks Most tasks Some tasks Most tasks All tasks were
completed were were were incomplete or
correctly in completed completed incomplete or incorrect.
given time correctly. correctly and incorrect and
and have a Tasks could have an have no Didn’t
complete be improved incomplete understanding perform tasks
understanding further and understanding and have no
have a understanding
complete
understanding
Total
45