2b Codes
2b Codes
Codes
2b-1
Quick links to each section
1. Encoding information
2. Straight Binary Coding
3. Binary-coded-decimal (BCD) code
4. Gray code
5. Alphanumeric code
6. Parity Method for Error Detection
7. Commonly used prefixes
2b-2
Encoding
Numbers, letters or words are represented by a special
group of symbols. A group of symbols is called a code.
For example, you may use the following binary code with
your friend:
00: let’s go eat lunch
01: let’s go play basketball
10: let’s go to the library
11: let’s study for tomorrow’s quiz
Both you and your friend must agree what each code word
means for it to work.
2b-3
Straight binary coding
In digital systems, numbers are probably the most common
type of information that need to be represented.
It is very common to represent a numerical value in binary,
i.e. base-2.
e.g. the decimal value 35 is simply represented as 100011 in
binary. This is called straight binary coding or simply binary
coding.
Note: 3510 = 2^5 + 2^1 + 2^0
2b-4
Binary-Coded-Decimal Code (BCD)
2b-5
Decimal digit BCD equivalent
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
2b-6
Notice that the following bit patterns are illegal
in BCD code:
1010
1011
1100
1101
1110
1111
2b-8
Characteristics of BCD
• Relative ease of conversion
• Consists of groups of 4-bit codes for decimal
digits 0-9
• Important from hardware standpoint – logic
circuits perform conversion to and from decimal
digits, all digits can be converted simultaneously
• E.g. converting 957 to binary requires repeated
division, but converting it to BCD does not.
2b-9
BCD code is not used in
2b-10
Exercise
Answers:
0011 0100
0001 1001. 0010 0101
2b-11
Gray code
2b-12
Decimal 4-bit Gray code
0 0 0 0 0
1 0 0 0 1
2 0 0 1 1
3 0 0 1 0
4 0 1 1 0
5 0 1 1 1
6 0 1 0 1
Only 1 bit is
7 0 1 0 0 changed from
8 1 1 0 0 one value to the
9 1 1 0 1 next
10 1 1 1 1
11 1 1 1 0
12 1 0 1 0
13 1 0 1 1
14 1 0 0 1
15 1 0 0 0
2b-13
Example - Error occurring while using BCD
• what happens when a number increments from 1 to
2?
BCD code
Dec b3 b2 b1 b0
1 0 0 0 1
2 0 0 1 0
2b-14
Example - Error occurring while using BCD
• what happens when a number increments from 1 to
2?
Dec b3 b2 b1 b0
1 0 0 0 1
2 0 0 1 0
No error
2b-15
• possible actual case, bit b0 changes before b1:
Dec b3 b2 b1 b0
1 0 0 0 1
0 0 0 0 0
2 0 0 1 0
2b-16
Solution - Error occurring while using BCD
• Use Gray code instead and there will be no such
problem since only 1 bit (b1) is changed when the
number increments from 1 to 2
Gray code
Dec b3 b2 b1 b0
1 0 0 0 1
2 0 0 1 1
2b-17
Gray code is useful in situations where
multiple bit change may lead to error.
2b-18
Alphanumeric Codes
• Codes that represent
– alphabet (e.g. a, b, c, …, z)
– punctuation marks
– special characters and numbers
• A complete set of alphanumeric code must include
– 26 lowercase letters (a – z)
– 26 uppercase letters (A – Z)
– 10 numeric digits (0 – 9)
– 7 punctuation marks
– 20 – 40 other characters such as +, -, /, <, #, %, …
2b-19
ASCII Code
• Most widely used alphanumeric code
• 7-bit code, hence 128 (=27) possible code symbols
• There is also the 8-bit extended ASCII code
• Used for transferring alphanumeric data between
digital devices
• Used in digital computers to store alphanumeric
characters
2b-20
b7 is MSB, b1 is LSB
2b-21
Example:
Mp3 encoded into ASCII, will become
100110111100000110011
M p 3
2b-22
Often times, hexadecimal digits are used to
represent ASCII codes.
Example:
Character ASCII expressed in Hex
M 0100 1101 4D
p 0111 0000 70
3 0011 0011 33
2b-23
Different ways to represent 1410
2b-24
Parity Method for Error Detection
Actual signal
Received signal
2b-25
• Result of error:
transmitted 0 becomes 1 at the receiver
transmitted 1 becomes 0 at the receiver
• e.g. 1010 wrongly received as 1011, or
1100 wrongly received as 1000
2b-26
Parity Bit
0 0 1 0 1 0 1 1
4 bits of 1 in data (4
Parity bit
is an even number)
2b-27
• Odd parity make total no. of ‘1’ bits odd BEFORE
transmitting
1 1 0 1 1 1 1
1
6 bits of 1 in data (7
Parity bit is an odd number)
2b-28
Examples:
7-bit data 8-bits are transmitted after
to be adding parity bit
transmitted
Odd parity Even parity
1001000 11001000 01001000
0011100 00011100 10011100
0101110 10101110 00101110
1010111 01010111 11010111
2b-29
Example: Limitation of parity method
SI units IEC
• k (kilo) = 103 • Ki (kibi) = 210
• M (mega) = 106 • Mi (mebi) = 220
• G (giga) = 109
• Gi (gibi) = 230
JEDEC • Ti (tebi) = 240
• K (kilo) = 210
• M (mega) = 220
• G (giga) = 230 Binary prefix - Wikipedia, the free
encyclopedia
• T (tera) = 240
2b-31
Commonly Used Prefixes (cont)
Metric system
• m (milli) = 10-3
• µ (micro) = 10-6
• n (nano) = 10-9
• p (pico) = 10-12
Example:
• 0.1 µs = 100 ns = 10-7 second
• 200 mV = 0.2 V
2b-32
About significant figures
2b-33