BIT102 SLM Library - SLM - Unit 03
BIT102 SLM Library - SLM - Unit 03
3.1 Introduction
In the previous unit we studied different types of number systems and
conversion of numbers from one number system into the other. We also
studied negative number representation and arithmetic operations using 1’s
and 2’s complements. Computers play a very important role in modern IT
world and have touched every part of our lives. We know that digital
systems use signals that have two separate or distinct values and the
corresponding circuit elements have two stable states. We can represent
any information using binary code (i.e., a pattern of 0’s and 1’s). The codes
must be in binary because, digital circuits manipulate patterns of 0’s and 1’s.
However, it must be realized that binary codes merely change the symbols,
not the meaning of the elements of information that they represent. If we
inspect the bits of a computer at random, we will find that most of the time
they represent some type of coded information rather than binary numbers.
Computers and other digital circuits process data in binary format. Various
binary codes are used to represent data which may be numeric, alphabetic
or special characters. Codes are also used for error detection and error
correction in digital systems. Although, the information is represented in
binary form, the interpretation of data is possible only if the code in which
the data is being represented is known. For example, the binary number
1000010 represents 66 (decimal) in straight binary, 42 (decimal) in BCD,
and letter B in ASCII code. Hence, while interpreting the data, one must be
very careful regarding the code used. In this unit, we will discuss some of
the commonly used digital codes namely BCD, Gray code and
alphanumeric codes.
Objectives:
After studying this unit, you should be able to:
discuss the importance of BCD code
convert a given gray code to binary and vice versa
illustrate the use of ASCII code
discuss EBCIDIC code
list and compare different error detection codes.
We observe from the table 3.1 that only ten codes from 0000 to 1001 are
valid in BCD. The remaining codes 1010, 1011, 1100, 1101, 1110 and 1111
are not allowed in BCD and hence these six codes are invalid codes.
The advantage of the BCD encoding is that the conversion of binary
sequence to decimal digits for printing or display is easier and also the
decimal calculations will be faster. The drawbacks of the BCD encoding are
the complexity of the digital circuits which are used to implement the
mathematical operations increases, and because of a relative inefficient
encoding than a pure binary representation, BCD requires more space.
Decimal to BCD Conversion:
The following example illustrates the conversion of decimal number to BCD
code.
Example 3.1: Convert (6838)10 into its BCD equivalent
6 8 3 8 ← Decimal Number
9 6 7 9 : Decimal
BCD Subtraction
In BCD subtraction, each difference should be less than or equal to 9 (1001).
If it exceeds 9, then 6 (0110) is subtracted from that difference.
Example 3.5: Subtract (45)10-(18)10 in BCD
Decimal BCD subtraction
45 → 0100 0101
- 18 → 0001 1000
27 0010 1101 → Invalid BCD
- 0110 → subtract 0110
0010 0111 → Valid BCD
0010 1110 which is 27 in decimal is the answer.
Packed BCD and Unpacked BCD: A packed BCD uses two digits per byte
where as an unpacked BCD uses one digit per byte.
For example, consider the decimal number 79.This can be put in packed
and unpacked format as follows:
Decimal Number: 7 9
Packed BCD: 0111 1001
Un Packed BCD: 0000 0111 0000 1001
To convert a two-byte unpacked BCD number into a single byte packed
BCD number, shift the upper byte left four times, then perform logic OR
operation with the results with the lower byte.
Decimal to Packed BCD Conversion:
To convert a decimal number into a packed BCD number, assign each digit
of the decimal to its 4-bit equivalent, adding zeroes to the upper nibble if
necessary. For example, consider the number 235. This number can be put
in Packed BCD format as follows:
Decimal Number: 2 3 5
Packed BCD: 0000 0010 0011 0101
Decimal to Unpacked BCD conversion: To convert a decimal number into
an unpacked BCD number, assign each decimal digit its 8-bit binary
equivalent. Now consider the number 235. This can be put in unpacked
BCD as follows:
Decimal Number: 2 3 5
Packed BCD: 0000 0010 00000011 00000101
Self-Assessment Questions
1. In BCD, each decimal digit is represented by a ______ bit binary code.
2. In BCD, which of the following codes is invalid?
(a) 1000 (b) 1011 (c) 0101 (d) 1001
3. The BCD code for decimal number (6838)10 is _________________.
4. The BCD code 1001011000010101 represents __________ in decimal.
5. ______________ systems store the most significant byte of a word in
the smallest address and the least significant byte is stored in the
largest address.
6. For the decimal number 235, the packed BCD is ________________.
It is observed from the table 3.2 that there is only one bit change between
two successive numbers in the sequence. This is the unique property of the
Gray code. For example, if we consider the Gray codes 010 and 110, there
is only one bit change in the Gray code bit G2. Similarly, when we consider
the next codes 110 and 111, there is a single bit change in Gray code bit
G0. In other words, there is only one bit in the code group that changes
while going from one number to the next. Hence it is called unit distance
code.
Gray
1 0 1
Code
Binary
1 1 0 0 1 0
Number
↓
Gray
1 0 1 0
Code
Binary
1 1 0 0 1 0
Number
↓
Gray
1 0 1 0 1
Code
Binary
1 1 0 0 1 0
Number
↓
Gray
1 0 1 0 1 1
Code
Binary
1 1 0 0 1
Number
Gray
1 0 1 0 1 1
Code
↓
Binary
1 1 0 0 1 0
Number
Example 3.10: Convert the Gray Code 11100110 into binary code.
Self-Assessment Questions
7. The ______________ code is an unweighted code.
8. The Gary code is called unit distance code because there is a single bit
change when we go from one code to the next successive code.
(State true or false)
9. The Gray code for binary number110010 is ___________________.
affect how text is processed. So all the standard keyboard characters and
control functions like return and linefeed functions can conveniently be
represented with different code groups. The table 3.3 shows the partial
listing of ASCII code. The table also shows the hexadecimal and octal
equivalents.
Table 3.3: Partial listing of ASCII code.
EBCDIC Code
EBCDIC pronounced as ‘eb-si-dik stands for Extended Binary Coded
Decimal Interchange Code. It is also alphanumeric code used by IBM
mainframes for its operating systems. EBCDIC is an 8 bit character coding
and represents 28=256 combinations. However several combinations are
not being used. EBCDIC has more control characters compared to ASCII.
Although EBCDIC is not widely used with personal computers, it is well-
known and recognized primarily as an IBM code for the corporation's
mainframes and minicomputers. EBCDIC currently exists in at least six
mutually incompatible versions. Although most characters are the same in
ASCII and EBCDIC, some ASCII characters do not exist in EBCDIC
(e.g., square brackets--[]) and EBCDIC contains some characters (e.g., the
"cent" sign--¢--and the "not" sign--¬) that are not in ASCII.
The character encoding is based on Binary Coded Decimal (BCD), so the
contiguous characters in the alphanumeric range are formed up in blocks of
up to 10 from 0000 binary to 1001 binary. Non alphanumeric characters are
almost all outside the BCD range.
There are four main blocks in the EBCDIC code page: 0000 0000 to 0011
1111 is reserved for control characters; 0100 0000 to 0111 1111 for
punctuation; 1000 0000 to 1011 1111 for lowercase characters and 1100
0000 to 1111 1111 for uppercase characters and numbers.
The table 3.4 shows the partial listing of EBCDIC code.
UNICODE:
We know that digital computers deal with numbers. They store letters and
other characters by assigning a number for each one. Though there are
hundreds of different encoding systems for assigning these numbers, no
single encoding scheme contains enough characters. The Encoding
In the figure 3.5, it can be observed that the original data sent from
transmitter gets distorted due to noise and error data signal is represented
as x. Error detection techniques detect such errors, and error correction
enables reconstruction of the original data.
The general definitions of the terms are as follows:
Error detection is the detection of errors caused by noise or other
impairments during the data transmission from the transmitter to the
receiver.
Error correction is the detection of errors and reconstruction of the
original data that is free of errors.
Usually binary information will be transmitted through communication
medium, e.g. using wires or wireless media. When noise gets added, the
bits get corrupted and may change from 0 to 1 or vice versa. So to detect
the errors at the receiver’s end, the sender sends an extra bit called parity
bit attached to the original binary message. A parity bit attached to the n-bit
binary message makes the total number of 1’s in the message (including the
parity bit) either odd or even. If the parity bit makes the total number of 1’s
an odd number, it is called odd parity. If the parity bit makes the total
number of 1’s even number, it is called even odd parity.
For example, suppose that we want to transmit the data 1000011. This is
the ASCII character “C.” The data has three 1s which is an odd number.
Therefore, we will add a parity bit of 1 to make the total number of 1s an
even number. This means it is an even parity. The new code group,
including the parity bit, thus becomes
1 1 0 0 0 0 1 1
↓ ↓
Parity Bit Message Data
In case of odd-parity the parity bit is chosen such that the total number of 1s
(including the parity bit) is an odd number. For example, for the code group
1000001, we assign parity bit 1 to make it an odd parity. Now for the code
group 1000011, the total number of 1’s an odd number. So the parity bit 0
will be attached to this number. Regardless of whether even parity or odd
parity is used, the parity bit becomes an actual part of the code word.
The parity bit is used to detect any single-bit errors that occur during the
transmission of a data from one location to another. For example, suppose
that the character “A” is being transmitted and odd parity is being used.
The transmitted code would be
11000001
When the receiver circuit receives this code, it will check that the code
contains an odd number of 1s (including the parity bit). If so, the receiver will
assume that the code has been correctly received. Now, suppose that
because of some noise or malfunction the receiver actually receives the
following code:
11000000
The receiver will find that this code has an even number of 1s. This tells the
receiver that there must be an error in the code because presumably the
transmitter and receiver have agreed to use odd parity. There is no way,
however, that the receiver can tell which bit is in error because it does not
know what the code is.
Parity method would not work if two bits were in error. This is because two
errors would not change the “oddness” or “evenness” of the number of 1s in
the code. Usually the parity method is used only in situations where the
probability of a single error is very low and the probability of double errors is
essentially zero.
In general, a transmitted message with even number of errors cannot be
detected by the parity bit.
In parity method, it is assumed that the transmitter and the receiver have
agreed, in advance, as to whether odd or even parity is being used.
The table 3.5 shows the required odd parity and even parity for a 3-bit
message.
Table 3.5: Odd and even parity
Now the message 010 with odd parity will be 0010. Similarly, message 010
with odd parity will be 1010.
Self-Assessment Questions
15. _________________is the detection of errors caused by noise or other
impairments during transmission from the transmitter to the receiver.
16. In case of odd-parity the parity bit is chosen such that the total number
of 1s (including the parity bit) is an odd number. (State true or false)
17. The message 010 with odd parity will be sent as ______________.
3.6 Summary
Let us recapitulate the important concepts discussed in this unit:
In BCD, each decimal digit is represented by a four bit binary code.
The drawbacks of the BCD encoding are the complexity of the digital
circuits which are used to implement the mathematical operations.
Big-endian systems store the most significant byte of a word in the
smallest address and the least significant byte is stored in the largest
address.
3.8 Answers
Self-Assessment Questions
1. Four
2. 1011
3. 0110100000111001(BCD)
4. 9615
5. Big-endian
6. 0000 0010 00000011 00000101
7. Gray
8. True
9. 101011
10. Alphanumeric
11. American Standard Code for Information Interchange
12. EBCDIC
13. 4E
14. Unicode
15. Error detection
16. True
17. 0010
Terminal Questions
1. A BCD is a code in which each decimal digit is represented by a four bit
binary code. Refer to section 3.1 for more details.
2. (a) 678= 0110 0111 1000 (b) 2728= 0010 0111 0010 1000
(c) 5698= 0101 0110 1001 1000.
Refer to section 3.2 for more details.