100% found this document useful (17 votes)
194 views

Computer Codes

Computer Codes

Uploaded by

Ms.DEVI P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (17 votes)
194 views

Computer Codes

Computer Codes

Uploaded by

Ms.DEVI P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

NUMBER SYSTEMS

Computer Codes
 Computer codes are used for internal representation of data in computers
 As computers use binary numbers for internal data representation, computer codes use
binary coding schemes
 In binary coding, every symbol that appears in the data is represented by a group of bits
 The group of bits used to represent a symbol is called a byte
 As most modern coding schemes use 8 bits to represent a symbol, the term byte is often
used to mean a group of 8 bits

 Commonly used computer codes are BCD, EBCDIC, and ASCII


BCD CODE

 BCD stands for Binary Coded Decimal

 It is one of the early computer codes

 It uses 6 bits to represent a symbol

 It can represent 64 (26) different characters


Defination of BCD (Binary Coded Decimal)
Binary coded decimal (BCD) is a system of writing numbers that assigns a four-digit binary code to each
digit 0 through 9 in a decimal (base-10) numeral. The four-bit BCD code for any particular single base-10
digit is its representation in binary notation, as follows:
• 0 = 0000
• 1 = 0001
• 2 = 0010
• 3 = 0011
• 4 = 0100
• 5 = 0101
• 6 = 0110
• 7 = 0111

• 8 = 1000

• 9 = 1001
Numbers larger than 9, having two or more digits in the decimal system, are expressed digit by
digit. For example, the BCD rendition of the base-10 number 1895 is

1 8 9 5

0001 1000 1001 0101


Why BCD is Used...

1. It is easy to encode and decode decimals into BCD and vice versa. It is also simple
to implement a hardware algorithm for the BCD converter.

2. It is very useful in digital systems whenever decimal information is given eitheras


inputs or displayed as outputs.

3. Digital voltmeters, frequency converters and digital clocks all use BCD as they display
output information in decimal
BCD Addition
BCD is a numerical code which has several rules for addition. The rules are given below in three
steps with an example to make the idea of BCD Addition clear.

1.At first the given number are to be added using the rule of binary. For example
BCD Addition

If the four bit result of addition is greater than 9 and if a carry bit is present in the result
then it is invalid and we have to add 6 whose binary equivalent is (0110)2 to the result of
addition. Then the resultant that we would get will be a valid binary coded number. In case
1 the result was (1111)2 which is greater than 9 so we have to add 6 or (0110)2 to it.
BCD Substraction
• At first 1’s compliment of the subtrahend is done, which is 1101 1110 1001 and is added to 0101 0100
0001. This step is called adder 1.
• Now after addition if any carry occurs then it will be added to the next group of numbers towards MSB.
Then EAC will be examined. Here, EAC = 1. So the result of addition is positive and true result of adder
1 will be transferred to adder 2.
• Now notice from LSB. There are three groups of four bit numbers. 1010 is added 1011 which is the
first group of numbers because it do not have any carry. The result of the addition is the final answer.

• Carry 1 will be ignored as it is from the rule.


• Now move to the next group of numbers. 0000 is added to 0010 and gives the result 0010. It is the final
result again.
• Now again move to the next group here 0000 is also added to 0011 to give the final result 0011.
Error Detection and Error Correction

 Why we need Error Detection?


 What are the Errors?
 What are the Error Detection Mechanisms?
 Parity Check
 Single Parity Check
 Two Dimensional Parity Check
 Drawbacks of Parity
Error Detection

• Data can be corrupted during transmission. Even with best prevention


methods.

• For a reliable communication, errors must be detected and corrected.


• Error detection and correction are implemented either at data link layer or
the transport layer of the OSI model.
Types of Errors

• Single bit error :-


- Only one bit in the data unit has changed.

0 changed to 1

Received Sent
Types of Errors

• Burst error :-
- It means that two or more bits in the data unit has changed.

Sent

Bits corrupted by Burst Error

Received
Error Detection Codes
• Error detecting code is to include only enough redundancy to allow the receiver to deduce that an
error occurred, but not which error, and have it request a re- transmission.

• Used in Low Noisy Channels – Fiber Optics

• Error detection uses the concept of redundancy, which means adding extra bits for detecting
error at the destination

• To detect an error, something extra has to be added to the data/signal


• This extra is an error detection code
• 3 Techniques are there: Parity Check, Check Sum, CRC
Parity Check

• The Simplest method Available - it’s a linear, systematic block code


• 2 Parity Check Methods are there:
• Simple Parity - For Single bit Errors
• Two Dimensional - For Burst Errors

• How to use Parity Methods?


• Parity Generate – Sender’s Side
• Parity Detect – Receiver’s Side
Single Parity Check (VRC)
Vertical Redundancy Check

• In Single parity check, a parity bit is added to every data unit so that the total
number of 1s is even or odd.
11010011 1 Additional Bit added(PARITY BIT)

Information(1 byte – 8 bits)

• Therefore, the total number of bits transmitted would be 9 bits.


( 8 bits of information + 1 bit parity = n data bits into n+1 bits)
Single Parity check (Cont.)
Parity Generation

• There are two ways to generate a Single parity bit.


• One is called Even parity and the other is Odd parity.
• What is even parity?
• the total number of 1’s transmitted must be even.
• What is odd parity?
• the total number of 1’s transmitted must be odd
Parity Generation-VRC
• Parity bit is chosen so that the number of 1 bits in the code-word
is even (or odd)

• computing the (even) parity bit as the modulo 2 sum or XOR of


the data bits.

• use XOR and XNOR logic gates in circuits to generate parity bits
in practically (in devices).
How is the even parity bit generated?
Total number of ‘1’s should be even.
If the byte that we want to transmit is: 10 10 110 1
• Step 1:count the number of 1’s in the byte.
• Answer: 5
• Step 2: compute the parity value. 10 10 110 1 1
• Since the total number of 1’s is 5, the even parity bit will have a value of 1.
• If the number of bits are already even, the parity bit will be ‘0’.
How is the odd parity bit generated?
Total number of ‘1’s should be odd.

If the byte that we want to transmit is: 10 10 110 0


• Step 1:count the number of 1’s in the byte.
• Answer: 4
• Step 2: compute the parity value. 10 10 110 0 1
• Since the total number of 1’s is 4, the odd parity bit will have a value of 1.
• If the number of bits are already odd, the parity bit will be ‘0’.
ERROR DETECTION

• The reliability of a memory unit is improved by using error‐detecting and


error‐correcting codes.

• Most common error detection scheme is the parity bit.

• The parity of the word is checked after reading it from memory. The data word is
accepted if the parity of the bits read out is correct. If the parity checked results in an
inversion, an error is detected, but it cannot be corrected.
ERROR CORRECTION
• An error‐correcting code generates multiple parity check bits that are stored with the data word
in memory.

• Each check bit is a parity over a group of bits in the data word.

• When the word is read back from memory, the associated parity bits are also read from memory
and compared with a new set of check bits generated from the data that have been read.

• If the check bits are correct, no error has occurred.

• If the check bits do not match the stored parity, they generate a unique pattern, called a
syndrome, that can be used to identify the bit that is in error.
Hamming Code
• k parity bits are added to an n ‐bit data word, forming a new word of n + k bits.

• The bit positions are numbered in sequence from 1 to n + k.

• Those positions numbered as a power of 2 are reserved for the parity bits. The remaining bits

are the data bits. The code can be used with words of any length.

• Consider, for example, the 8‐bit data word 11000100. We include 4 parity bits with the 8‐bit

word and arrange the 12 bits as follows:

• Bit position:

1 2 3 4 5 6 7 8 9 10 11 12
P1 P2 1 P4 1 0 0 P8 0 1 0 0
The Parity bits are

P1 = XOR of bits (3, 5, 7, 9, 11) = 0

P2 = XOR of bits (3, 6, 7, 10, 11) = 0

P4 = XOR of bits (5, 6, 7, 12) = 1

P8 = XOR of bits (9, 10, 11, 12) = 1

• The 8‐bit data word is stored in memory together with the 4 parity bits as a 12‐bit composite word.

• When the 12 bits are read from memory, they are checked again for errors. The parity is checked over
the same combination of bits, including the parity bit.
• Bit Position
0 0 1 1 1 0 0 1 0 1 0 0
1 2 2 4 5 6 7 8 6 10 11 12
• The Check bits are

C1 = XOR of bits (1, 3, 5, 7, 9, 11) = 0

C2 = XOR of bits (2, 3, 6, 7, 10, 11) = 0

C4 = XOR of bits (4, 5, 6, 7, 12) = 0

C8 = XOR of bits (8, 9, 10, 11, 12) = 0

• A 0 check bit designates even parity over the checked bits and a 1 designates odd parity.

• Since the bits were stored with even parity, the result, C = C8C4C2C1 = 0000, indicates that no error has
occurred.

• if C ≠ 0, then the 4‐bit binary number formed by the check bits gives the position of the erroneous bit.

• Bit position: 1 2 3 4 5 6 7 8 9 10 11 12
0 0 1 1 1 0 0 1 0 1 0 0 No error
1 0 1 1 1 0 0 1 0 1 0 0 Error in bit 1
0 0 1 1 0 0 0 1 0 1 0 1 Error in bit 5
C8 C4 C2 C1

• For no error: 0 0 0 0

• With error in bit 1: 0 0 0 1

• With error in bit 5: 0 1 0 1

• When the binary number C is not equal to 0000, it gives the position of the bit in error.

• The error can be corrected by complementing the corresponding bit.

• The syndrome value C consists of k bits and has a range of 2k values between 0 and 2k - 1.

• One of these values, usually zero, is used to indicate that no error was detected, leaving 2k – 1 values
to indicate which of the n + k bits was in error.

• The range of k must be equal to or greater than n + k, giving the relationship

2k – 1-K ≥n
Range of Data Bits for k Check Bits
Number of Check Bits, k Range of Data Bits, n
3 2–4
4 5–11
5 12–26
6 27–57
7 58–120

Single‐Error Correction, Double‐Error Detection

• The Hamming code can detect and correct only a single error. By adding another parity bit to the coded
word, the Hamming code can be used to correct a single error and detect double errors.
• If this additional parity bit is included, then the previous 12‐bit coded word becomes
001110010100P13. This produces the 13‐bit word 0011100101001 (even parity).
• P = 0, the parity is correct (even parity)
• P = 1, then the parity is incorrect (odd parity)

• If C = 0 and P = 0, no error occurred.

• If C ≠ 0 and P = 1, a single error occurred that can be corrected.

• If C ≠ 0 and P = 0, a double error occurred that is detected, but that cannot be corrected.

• If C = 0 and P = 1, an error occurred in the P13 bit.

• This scheme may detect more than two errors, but is not guaranteed to detect all such errors.

• Integrated circuits use a modified Hamming code to generate and check parity bits for single‐error
correction and double‐error detection.
Drawbacks

• Both simple parity and 2D parity do not catch all the errors.

• Simple parity only catches odd numbers of bit errors, and can not catch if 2
bits interchanged.

• 2D parity is better at catching errors, but requires too many check bits added
to a block of data.

• Can not use in 4 bit errors and more bit errors in some cases.
WHAT IS A BINARY CODE ?

• A binary code represents text or computer processor instructions using


the binary number system's two binary digits, 0 and 1. The binary code
assigns a bit string to each symbol or instruction.
WHAT IS A GRAY CODE?

• The reflected binary code(RBC), also known as Gray code after Frank
Gray, is a binary numeral system where two successive values differ in only
one bit. This code was originally designed to prevent spurious output from
electromechanical switches.
THE GRAY CODE
Binary-to-Gray code conversion
• The MSB in the Gray code is the same as corresponding MSB in the binary
number.
• Going from left to right, add each adjacent pair of binary code bits to get
the next Gray code bit. Discard carries.
CONVERTING CIRCUIT

• Binary to Gray conversion is accomplished with 2 XOR gates.


LOGIC DIAGRAM OF 4 BIT BINARY TO GRAY CODE
CONVERTER
TRUTH TABLE

You might also like