Binary codes

GargiKhanna1 2,497 views 25 slides Sep 13, 2020
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

Classification of Binary codes


Slide Content

Dr. (Mrs.) Gargi Khanna
Associate Professor
Electronics & Communication Engg. Deptt..
National Institute of Technology Hamirpur
(HP)



By:-

oCodes
oWeighted and unweighted codes
oBCD, Excess-3, 2421, 84-2-1
oGray Code
oAlphanumeric Code, Unicode

Code:A set of n-bit strings in which different bit strings
represent different numbers or other things.
Code word: a particular combination of n-bit values
N-bit strings =2
N
valid code words.
To represent 10 decimal digits, at least need 4 bits.
Excessive ways to choose ten 4-bit words. Some
common codes:
BCD: Binary-coded decimal, also known as 8421 code
2421,5421, Excess-3, Gray,
Codes can be used to represent:
Numericals, Nonnumerical texts, Symbols
Events/Actions/States/Conditions

In weighted code, each digit position has a weight
or value. The sum of all digits multiplied by a
weight gives the total amount being represented.


We can express any decimal number in tens,
hundreds, thousands and so on.
Eg:- (4327)
10= 4(10³)+3(10²)+2(10¹)+7(10
0
)
BCD or 8421 is a type of weighted code where each
digit position is being assigned a specific weight.

Positively weighted codes: All the weights asigned
to binary bits are positive
17 positively weighted codes
The first weight must be 1, second weight must be 1 or
2 and the sum of all weights must be equal and greater
than 9
Eg 8421, 2421, 5211, 3321, 4311.
Negatively weighted codes: some of the weights
assigned to binary bits are negative
Eg 642-3, 84-2-1,74-2-1, 631-1

In non-weighted code, there is no positional weight i.e.
each position within the binary number is not assigned
a prefixed value. No specific weights are assigned to bit
position in non –weighted code.
The non-weighted codes are:-
a) The Gray code b) The Excess-3 code

Four bits are used to represent each decimal digit
In each 4-bit group, 6 values are not used
Many possible codes, natural BCD 8421 (equivalent
binary digits) most common
BCD is not as efficient as binary
BCD is easy to convert to/from decimal (it really is
decimal with different symbols)
BCD add/subtract circuits are complex

Decimal
digit
BCD
8421 2421 5421 8 4 -2 -1 6 4 2 -3
Excess-
3
0 0000 0000 0000 0000 0000 0011
1 0001 0001 0001 0111 0101 0100
2 0010 0010 0010 0110 0010 0101
3 0011 0011 0011 0101 1001 0110
4 0100 0100 0100 0100 0100 0111
5 0101 1011 1000 1011 1011 1000
6 0110 1100 1001 1010 1000 1001
7 0111 1101 1010 1001 1101 1010
8 1000 1110 1011 1000 1010 1011
9 1001 1111 1100 1111 1111 1100
Positively Weighted codes Unweighted code
Negatively Weighted codes

Convert following to BCD form
a) 5673
10 b) 342
10 c) 218
10

Convert following BCD to their decimal equivalent
a) 10000110 b) 00110010.10010100

Convert the following binary numbers to
their BCD equivalent.
a) 1101.01
2 b) 11.011
2
(Binary to decimal, then decimal to BCD)

The codes representing the pair of complementary digits
are also complementary to each other.
Example: Excess-3 code
0: 0011
1: 0100
2: 0101
3: 0110
4: 0111
5: 1000
6: 1001
7: 1010
8: 1011
9: 1100
241: 0101 0111 0100
758: 1010 1000 1011

Gray codes are minimum change codes
From one numeric representation to the next,
only one bit changes
Primary use is in numeric input encoding apps.
where we expect non-random input values
changes (I.e. value n to either n-1 or n+1)
Rotary shaft position

Binary to gray conversion:-
a)The MSB in the Gray code is same as the
corresponding bit in the binary number.
b)Going from left to right, add each adjacent pair of
binary bit to get next gray code bit and discard
carry

Gray to binary conversion:-
a)The MSB is the binary code is
same as corresponding digit in the gray code.
b)Add each binary digit generated to the gray digit
in the next adjacent position and discard carry.

Binary

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
Gray

0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000

Gray Code
0 = 0000
1 = 0001
2 = 0011
3 = 0010
4 = 0110
5 = 1110
6 = 1010
7 = 1011
8 = 1001
9 = 1000
A Gray code changes by only 1 bit for
adjacent values. This is also called a
‘thumbwheel’ code because a
thumbwheel for choosing a decimal
digit can only change to an adjacent
value with each click of the
thumbwheel. This allows the binary
output of the thumbwheel to only
change one bit at a time; this can help
reduce circuit complexity, reduce signal
noise and result in less switching
events. Less switching results in
reduction in power dissipation

Binary codes used to represent alphabetic and numeric
characters, symbols, control function
Most common are:
ASCII, 7 bit code, 128 symbols
EBCDIC, 8 bit code, 256 symbols
Unicode, 16 bit code
Problems can arise when comparing symbol values
(collation)
Comparing ‘A’ to ‘a’ in ASCII system yields different
results in an EBCDIC system.

ASCII table
CS2100 Number Systems and Codes 18 MSBs
LSBs000001010011100101110111
0000NULDLESP 0 @ P ` p
0001SOHDC1 ! 1 A Q a q
0010STXDC2“ 2 B R b r
0011ETXDC3# 3 C S c s
0100EOTDC4$ 4 D T d t
0101ENQNAK % 5 E U e u
0110ACKSYN & 6 F V f v
0111BELETB ‘ 7 G W g w
1000BSCAN ( 8 H X h x
1001HTEM ) 9 I Y i y
1010LFSUB * : J Z j z
1011VTESC + ; K [ k {
1100FFFS , < L \ l |
1101CR GS - = M ] m }
1110 O RS . > N ^ n ~
1111 SIUS / ? O _ oDEL
A: 1000001

Functions ASCII Extended Code
39 Equivalent *
Hex Value Description
F1 17 $Q 11 DC1
F2 18 $R 12 DC2
F3 19 $S 13 DC3
F4 20 $T 14 DC4
F5 21 $U 15 NAK
F6 22 $V 16 SYN
F7 23 $W 17 ETB
F8 24 $X 18 CN
F9 25 $Y 19 EM
F10 26 $Z 1A SUB
F11 27 %B 1C FS
F12 28 %C 1D GS

UNICODE is a 16-bit code for representing
alphanumeric data. With 16 bits, can represent 65536
different symbols.
16 bits = 2 Bytes per character.

$0041-005A A-Z
$0061-4007A a-z
Some other alphabet/symbol ranges
$3400-3d2d Korean Hangul Symbols
$3040-318F Hiranga, Katakana, Bopomofo, Hangul
$4E00-9FFF Han (Chinese, Japenese, Korean)

UNICODE used by Web browsers, Java, most software
these days.

Due to the limitation of 7-bit ASCII code, American
National Standard Institute (ANSI) also extend the 7-
bit ASCII code to 8-bit code, known as Latin-I.
Latin-I is an ISO standard.
However, the 8-bit code still not adequate for
representing all possible characters in use Unicode.
Unicode can represent 65,536 characters, of which
approximately 49,000 have been defined.
More recent standard, Unicode 3.1 supports millions of
different characters.
Unicode is multilingual in the most global sense.

The usual floating point number
format consist of:
A sign bit.
An exponent
A mantissa.

Different input devices are used for converting original
data into computer format.
Keyboard: Generate binary number code for each key.
Microphone: Convert analog sound into binary data
using ADC.
Camera: Convert analog picture into binary data using
ADC.
Etc.

Many different standards in use for different types of data. Some
common data representation are:
Type of data Standard
Alphanumeric ASCII, EBCDIC, Unicode
Image (bitmap) GIF(graphical image format), TIFF (tagged
image file format), PNG (portable network
graphics)
Image (object) PostScript, JPEG, SWF (Macromedia Flash),
SVG.
Outline graphics and
fonts
PostScript, TrueType
Sound WAV, AVI, MP3, MIDI, WMA
Page description Pdf (Adobe Portable Document Format),
HTML, XML.
Video Quicktime, MPEG-2, WMV