4 Codes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Codes

Homework

1. How many address lines would a 64x8 RAM have?

2. How many 128x8 memory chips are needed to provide a memory capacity of

4096x16?

3. Which of the following multiplexers would have a 4-bit data selection input?
a. 4:1 mux b. 2:1 mux

c.16:1 mux d. 8:1 mux

2
1. How many address lines would a 64 x 8 RAM have?

Answer
A m x n RAM has n data output lines and k address input lines, where m=2k .
So, in case of a 64 x 8 RAM, m = 64

64 x 8
=> 2k = 64

=> 2k = 26 m n

=> k = 6

3
2. How many 128 x 8 memory chips are needed to provide a memory capacity
of 4096 x 16?

Answer

128 x 8 = 128 bytes

So, 4096 x 16 = 4096 x 2(8) = 4096 x 2 bytes.

We have a 128 byte memory chip and we need to create 4096 x 2 or 8192

bytes of memory using this chip. We therefore need 8192/128 = 64 chips

4
3. Which of the following multiplexers would have 4 input selection lines?

a. 4:1 mux b. 2:1 mux


c. 16:1 mux d. 8:1 mux
Answer

A 2n-by-1 mux has 2n input data lines and n input selection lines.

So, a 24-by-1 mux will have 4 input selection lines.

The correct option is c.

5
In this lecture, we will study

i. BCD

ii. Gray code

iii. Excess 3 code

iv. 2421 code

v. Excess 3 gray code

vi. Error detection codes


BCD – Binary Coded Decimal

7
Binary Coded Decimal
PACKED BCD UNPACKED BCD

0=0000 0=0000 0000


A BCD is a system of
1=0001 1=0000 0001
writing numerals that
2=0010 2=0000 0010
assigns a 4 (or 8) digit
3=0011 3=0000 0011
binary code to each
4=0100 4=0000 0100
digit of the decimal
5=0101 5=0000 0101
number system.
6=0110 6=0000 0110
7=0111 7=0000 0111
8=1000 8=0000 1000
9=1001 9=0000 1001
8
Binary Coded Decimal

For instance, in BCD, ’91’ would be represented as:

Decimal: 9 1
(Packed) BCD: 1001 0001
(Unpacked) BCD: 0000 1001 0000 0001

Please note that in BINARY, ’91’ would be represented as 1011011

9
Advantages of BCD
Disadvantages of BCD

BCD helps achieve a more


BCD causes small increase in
accurate representation
the complexity of the circuits
and rounding
needed to implement basic
of decimal quantities.
arithmetic operations.
It also enables easy
It also results in a slightly
conversion into human-
less dense storage.
readable representations.

10
Gray Code

11
Gray Code
0=0000 8=1100
Also known as a reflected binary
1=0001 9=1101
code, the Gray Code is an
ordering of the binary numeral 2=0011 10 = 1 1 1 1

system such that two successive 3=0010 11 = 1 1 1 0


values differ in only one bit. 4=0110 12 = 1 0 1 0
5=0111 13 = 1 0 1 1
Gray code is used in
6=0101 14 = 1 0 0 1
Analog to Digital Converters
and for Error Correction 7=0100 15 = 1 0 0 0

in digital communication.
12
Advantages of Gray Code
Disadvantages of Gray Code
With Gray code, the switching
activity is reduced (because The Gray code is not suitable
only one digit changes in for arithmetic operations.
consecutive code words). It also has limited practical
This results in low power use outside of a few
consumption, fast response, specific applications.
and reduced error in coding.

13
Gray to Binary Conversion

4-Bit Gray 4-Bit Binary

A B C D B4B3 B2B1
0=0 0 0 0 0=0 0 0 0
1=0 0 0 1 1=0 0 0 1
2=0 0 1 1 2=0 0 1 0
3=0 0 1 0 3=0 0 1 1
4=0 1 1 0 4=0 1 0 0
5=0 1 1 1 5=0 1 0 1
6=0 1 0 1 6=0 1 1 0
7=0 1 0 0 7=0 1 1 1
8=1 1 0 0 8=1 0 0 0
B4 = A (MSB remains the same) B3 = A + B 9=1 1 0 1 9=1 0 0 1
B2 = B3 + C B1 = B2 + D
14
Exercise

Convert Gray Code 1 1 1 0 into Binary

A B C D

1 1 1 0

+ + +

1 0 1 1
B4 B3 B2 B1

15
Binary to Gray Conversion

4-Bit Binary 4-Bit Gray

A B C D G4G3 G2G1
0=0 0 0 0 0=0 0 0 0
1=0 0 0 1 1=0 0 0 1
2=0 0 1 0 2=0 0 1 1
3=0 0 1 1 3=0 0 1 0
4=0 1 0 0 4=0 1 1 0
5=0 1 0 1 5=0 1 1 1
6=0 1 1 0 6=0 1 0 0
7=0 1 1 1 7=0 1 0 0
8=1 0 0 0 8=1 1 0 0
G4 = A (MSB remains the same) G3 = A + B 9=1 0 0 1 9=1 1 0 1
G2 = B + C G1 = C + D
16
Exercise

Convert Binary 1 0 1 1 into Gray Code

A B C D

1 + 0 + 1 + 1

1 1 1 0
G4 G3 G2 G1

17
2421

18
2421: A Weighted Code

2421 is an example of a weighted code. In a weighted code, the bits are


multiplied by the weights indicated (i.e., 2, 4, 2, and 1), and the sum of the
weighted bits gives the decimal digit.

For instance, the bit combination 1 1 0 1 when weighted by the respective


digits 2 4 2 1 gives the decimal equivalent 1 x 2 + 1 x 4 + 0 x 2 + 1 x 1 = 7.

19
2421: A Weighted Code

0=0000 5=1011
1=0001 6=1100
2=0010 7=1101
3=0011 8=1110
4=0100 9=1111

Note: The BCD code can be assigned the weights 8 4 2 1, which is why it is sometimes referred
to as the 8421 code.
20
Excess-3 Code

21
Excess-3 Code

BCD + 0011 = Excess-3 Code 0=0011 5=1000


1=0100 6=1001
2=0101 7=1010
3=0110 8=1011
4=0111 9=1100

22
ASCII Code

23
American Standard Code
for Information Interchange (ASCII)

ASCII is the standard


code commonly used
for the transmission of
binary information.

Each character is
represented by a 7-bit
code and usually an
eighth bit is inserted
for parity.
24
Error Detection Codes

25
Error Detection Codes

When binary information is transmitted through some form of


communication medium, it might get corrupted due to noise, which might
cause some of the bits to change from 1 to 0 and vice versa.

An error detection code is a binary code that detects such errors during
transmission.

26
Parity Bit

Parity bit is the most common


error correcting code.
A parity bit is an extra bit
included with a binary message
to make the total number of 1s
in the message either even or odd.

Parity Bit Generation


27
Parity Generation and Parity Checking

At the sending end, the message to be sent is applied to a parity generator,


where the required parity bit is generated. The message, including the parity
bit is then transmitted to its destination.

At the receiving end, all the incoming bits are applied to a parity checker,
that checks the proper parity adopted (even or odd).
An error is detected if the checked parity does not match the adopted parity.

28
29
Homework 1

Decode the following ASCII Code

1001010 1001111 1001000 1001110 0100000 1000100


1001111 1000101

30
Homework 2

Obtain the 9’s complement of the following


eight-digit decimal numbers:

12349876
90009951

31
Homework 3

Obtain the 10’s complement of the following


six-digit decimal numbers:

123900
000000

32
Homework 4

Perform the following subtractions using


9’s and 10’s complement methods.

1. 876-234
2. 456-1235

33
9’s Complement

9’s complement of a number is obtained by subtracting each of its digits


from 9.

For instance: 9‘s complement of 25 is 74


9’s complement of 345.45 is 654.54

34
10’s Complement

10’s complement of a number = 9’s complement of that number + 1.

For instance: 10‘s complement of 25 is 74+1= 75


10’s complement of 345.45 is 654.54+1=655.54

35
Subtraction Using 9’s Complement

Say, A = 718 and B = 123. Find A-B using 9’s complement.


Step 1: Find 9’s complement of B
999
-123
=876
Step 2: Add 9‘s complement of 123 to 718 (because 718-123 = 718+(-123)=
718+(9’s complement of 123)).
718 594
+876 + 1
=1594 => add the carry => 595
36
Subtraction Using 9’s Complement

When the answer has NO CARRY, the FINAL RESULT of subtraction is obtained by
TAKING 9’S COMPLEMENT OF THE ANSWER along with a NEGATIVE SIGN.
Say, A = 123 and B = 718, and we have to find A-B using 9’s complement.
Step 1: Find 9’s complement of B
999
-718
=281
Step 2: Add 9‘s complement of 718 to 123.
123
+281
= 404 => NO CARRY => so, the result is – (9’s complement of 404),
which is -(595). 37
Subtraction Using 10’s Complement

Say, A = 4567 and B = 1234. Find A-B using 10’s complement.


Step 1: Find 10’s complement of B
9999
-1234
= 8 7 6 5 + 1 = 8766
Step 2: Add 10‘s complement of 1234 to 4567.
4567
+8766
=13333 => drop the carry => The answer is 3333

38
Subtraction Using 10’s Complement

When the answer has NO CARRY, the FINAL RESULT of subtraction is obtained by
TAKING 10’S COMPLEMENT OF THE ANSWER along with a NEGATIVE SIGN.
Say, A = 1234 and B = 4567, and we have to find A-B using 10’s complement.
Step 1: Find 10’s complement of B
9999
-4567
= 5 4 3 2 + 1 = 5433
Step 2: Add 10‘s complement of 4567 to 1234.
1234
+5433
= 6667 => NO CARRY => so, the result is – (10’s complement of 6667),
which is -(3333). 39
In the next lecture, we will study…

i. Microoperations

ii. Register Transfer Language

iii. Register Transfer

iv. Bus and Memory Transfer

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy