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
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.
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
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