Lab 1 - DLD

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

National University of Computer and Emerging sciences

Course: Computer Logic and Design Lab Lab Instructor: Tarviha Fatima
Course Instructor: Mr. Salman Mubarik Lab 1
Section: CS-2F2 Total Marks : 20

Number Systems, Conventions, BCD, ASCII and Arithmetic Operations

Objectives of Lab
 Students should be able to understand decimal, binary, octal and hexadecimal number systems.
 They should get hold on the conventions used for numbers.
 Students get to practice Binary Coded Decimals and Alpha Numeric Codes.
 They get to exercise performing Arithmetic Operations on different number systems.

1. Number Systems
1.1. Binary Number System
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. e.g.
(11010)2 = 1x24 + 1x23 + 0x22 + 1x21 + 0x20
= 16 + 8 + 0 + 2 + 0
= (26)10

The binary system represents numbers using binary digits (bits) where each digit
corresponds to a power of two.

Another Example:

Binary: 1 1 1 0 0 1 0 1

Power of two: 27 26 25 24 23 22 21 20

Decimal: 128 64 32 16 8 4 2 1

 The total (in decimal) is 128 + 64 + 32 + 4 + 1 = 229


 Since we begin counting from zero, n bits can represent 2n values:
from 0 to 2n–1 inclusive (e.g. 256 values, from 0 to 255, for 8bits).
 Groups of bits form binary words
Conversion from decimal to binary
 Repeat division by 2

Example: Convert (29)10 to binary

– 29/2 = 14 remainder 1 (LSB)

– 14/2 = 7 remainder 0

– 7/2 = 3 remainder 1

– 3/2 = 1 remainder 1

– 1/2 = 0 remainder 1 (MSB)

(29)10 => (11101)2

1.2. Hexadecimal Number System


 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.

Example: Convert (B65F)16 to Decimal number.

(B65F)16 = 11x163 + 6x162 + 5x161 + 15x160

= 11x4096 + 6x256 + 5x16 + 15

= 45056 + 1536 + 80 + 15

= (46687)10
Table 1: Numbers with Different Bases

DECIMAL BINARY OCTAL HEX


NUMBER NUMBER NUMBER NUMBER
(base 10) (base 2) (base 8) (base 16)
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

1.3. Octal Number System

 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
such that:

Example: (i) Convert (24)8 in octal to Decimal number (base 10)

248 = 2x81 + 4x80

= (20)10

(ii) From decimal to octal

Repeat divide by 8:

 20/8 = 2 remainder 4 (LSB)


 2/8 = 0 remainder 2 (MSB)
 2010 = 248
2. Number Conventions

3. BCD
 It is a Binary Code to represent decimal digits 0-9
 It is used by Decimal Number Displays

 BCD Addition
(i) Decimal BCD
23: 0010 0011
45: 0100 0101
-----------------------------------
68: 0110 1000
(ii) Decimal BCD
23: 0010 0011
49: 0100 1001
-----------------------------------
72: 0110 1100

Here: 1100 is illegal BCD number

Solution:

Add a 0110 (6) to an invalid BCD number

Carry added to the most significant BCD digit

Decimal BCD
23: 0010 0011
49: 0100 1001
-----------------------------------
72: 0110 1100
6: 0110
-----------------------------------

72: 0111 0010

4. ASCII-8 Code
 Numbers 0 to 9
o ASCII 0110000 (30h) to 0111001 (39h)
 Alphabets a to z
o ASCII 1100001 (61h) to 1111010 (7Ah)
 Alphabets A to Z
o ASCII 1000001 (41h) to 1011010 (5Ah)
 Control Characters
o ASCII 0000000 (0h) to 0011111 (1Fh)
In-Lab Problems:

Number System Problems

1. List the binary, octal, and hexadecimal numbers of 22, 48, 60 and 72.

2. What is the decimal equivalent of the largest binary integer that can be obtained with
a) 11 bits and
b) 25 bits?

3. Convert the following numbers from the given base to the other three bases listed in the
table:

Decimal Binary Octal Hexadecimal


271.5126 ? ? ?
? 1100101.011 ? ?
? ? 576.3 ?

4. Perform the following conversion by using base 2 instead of base 10 as the intermediate
base for the conversion:
a) (753.4)8 to base 6.
b) (FE2.A)16 to octal
c) (231.3)4 to hexadecimal
d) (2007)10 to base 20.

Number Conventions Problems

1. What is the exact number of bits in a memory that contains?


(a) 96K bits.
(b) 640M bits.
(c) 4G bits.
(d) 8T bits.

BCD Problems

1. Represent the decimal numbers 694 and 835 in BCD.

2. Perform BCD addition of (24)BCD + (46)BCD.

3. Write the decimal equivalent for (110001)BCD.


ASCII Problems

1. What is the representation of the number 8 in binary in ASCII-8 format.

2. Write ASCII-8 Coding for the letter X.

3. Decode the following ASCII Codes:

(i). 1010011 1110100 1100101 1110110 1100101 0100000 1001010 1101111 1100010 1110011

(ii). 1000111 1101111 0100000 1000010 1100001 1100100 1100111 1100101 1110010 1110011

0100001

Arithmetic Operations Problems

1. Perform the following arithmetic operations.

a) (24)5 + (53)5
b) (4A)16 + (3F)16
c) 1010100 + 1000011
d) (537)8 – (164)8 Note: Perform subtraction without converting it into another base
e) (1000100)2 – (1010011)2 Note: Use subtraction with borrow
f) (84)16 – (2A)16
g) (15)8 * (44)8
h) (2B)16 * (C)16
i) (11011)2 * (10111)2

You might also like