Fundamentals of Electrical and electronic engineering Binary code,grey code,octal code Module - 1.2.ppt

njr200505 34 views 39 slides Jul 09, 2024
Slide 1
Slide 1 of 39
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
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39

About This Presentation

This ppt is about the fundamental of Electrical and electronic engineering


Slide Content

Binary Codes
Coding is the process of altering the characteristics
of information to make it more suitable for
intended application
Representation of data using 0’s and 1’s is called
binary code
Binary codes are classified as
Numeric codes
Eg: 8421,XS-3,Gray code
Alphanumeric codes
EBCDIC, ASCII

Binary codes may be
weighted
non weighted
Positively weighted –Assigned weights are
positive
Eg: 8421,2421,5211 etc
Negatively weighted-Some of the assigned
weights are negative
Eg:642-3,631-1 etc

Non weighted code
Does not obey positional weighting
principle
Eg: Excess 3 code(Xs-3), Gray code

BCD code( Binary Coded
Decimal)
The digits of a decimal number are encoded into
groups of binary digits
It is a weighted code
The weights attached are 8,4,2,1
Advantages
Ease of conversion
Disadvantage
Less efficient than pure binary
Invalid are : 1010,1011,1100,1101,1110,1111Decimal digit0 1 2 3 4
BCD 0000 0001 0010 0011 0100
Decimal digit5 6 7 8 9
BCD 0101 0110 0111 1000 1001

Excess-3 (XS-3) code
It is a non weighted code
The binary code word of it is corresponding to
8421 +3
Eg: 5= 0101 +0011 = 1000
The invalid states are:
0000,0001,0010,1101, 1110 &1111

Gray code
This is a non weighted code
It is not sutable for arithmetic operations
It is cyclic
Successive code differ in one bit position only
Good for error detection.DecimalBinaryGray CodeDecimalBinaryGray code
0 0000 0000 8 1000 1100
1 0001 0001 9 1001 1101
2 0010 0011 10 1010 1111
3 0011 0010 11 1011 1110
4 0100 0110 12 1100 1010
5 0101 0111 13 1101 1011
6 0110 0101 14 1110 1001
7 0111 0100 15 1111 1000

Binary-to-Gray Code Conversion
Retain most significant bit.
From left to right, add each adjacent pair of binary
code bits to get the next Gray code bit, discarding
carries.
Example: Convert binary number 10110 to Gray code.
(10110)
2 = 11101
Gray10110Binary

1 Gray 1+0110Binary

1 1 Gray 10+110Binary

11 1 Gray 101+10Binary

111 0 Gray 1011+0Binary

1110 1Gray

Gray-to-Binary Conversion
Retain most significant bit.
From left to right, add each binary code bit
generated to the Gray code bit in the next
position, discarding carries.
Example: Convert Gray code 11011 to binary.11011Gray

1 Binary 1 1011Gray
+
1 0 Binary 11 011Gray
+
10 0 Binary 110 11Gray
+
100 1 Binary 1101 1Gray
+
1001 0Binary
(11011)
Gray= (10010)
2

Alphanumeric Codes
Apart from numbers, computers also handle textual data.
Character set frequently used includes:
alphabets: ‘A’ .. ‘Z’, and ‘a’ .. ‘z’
digits: ‘0’ .. ‘9’
special symbols:‘$’, ‘.’, ‘,’, ‘@’, ‘*’, …
non-printable:SOH, NULL, BELL, …
Usually, these characters can be represented using 7 or 8
bits.
Used for transmitting data between computers and i/o
devices
Eg: ASCII,EBCDIC

ASCII (American standard Code for
Information Interchange)
ASCII: 7-bit, plus a parity bitfor error
detection (odd/even parity).CharacterASCII Code
0 0110000
1 0110001
. . . . . .
9 0111001
: 0111010
A 1000001
B 1000010
. . . . . .
Z 1011010
[ 1011011
\ 1011100

ASCII
ASCII table: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 |
1101CRGS - = M ] m }
1110 O RS . > N ^ n ~
1111SIUS / ? O _ oDEL

EBCDIC(Extended Binary Coded Decimal
Interchange code)
It is an 8 bit alphanumeric code
It can be used to encode all the symbols and
control characters
Because 2
8
= 256 bit patterns are available
A
I
R
C1
C9
D9
0
9
+
-
F0
F9
4E
6D

Error detecting and correcting code
When data transmitted through a channel, due
to noise they may be get corrupted
Error detection and correcting codes are used
to detect and correct errors
Encoding may be done for error correction
and error detection.
Eg: Parity code, Hamming code

Error Detecting Code (Parity)
The simplest technique for detecting errors
Implemented by adding an extra bit to each
word being transmitted
Odd Parity –Set to a 0 or a 1 such that the total
number of 1 bits in the word including the parity
bit is an odd number
Even Parity -Set to a 0 or a 1 such that the total
number of 1 bits in the word including the parity
bit is an even number

7 bit Hamming Code (Error correcting)
Three parity bits are added to transmit four
data bits
Parity is added at bit positions 2
0
(1),2
1
(2) and(
2
2
(4)
The word formed is
P1P2D3P4D5D6D7
D is data bits
P is parity bits

Hamming Code(2)
P1 is set to 0 or 1, so that it establishes even
parity over the bits 1,3,5,7(p1,d3,d5,d7)
P2 is set to 0 or 1, so that it establishes even
parity over the bits 2,3,6,7(p2,d3,d6,d7)
P4 is set to 0 or 1, so that it establishes even
parity over the bits 4,5,6,7(p4,d5,d6,d7)

Hamming code(3)
Eg:
Encode 0011 to hamming code
P1 P2D3P4D5D6D7
0 0 1 1
P1(P1,D3,D5,D7)-P1 001 1
P2(P2,D3,D6,D7)-P2 011 0
P4(P4,D5,D6,D7)-P4 011 0
Final code is 1000011

Decoding of Hamming code
At the receiving end the hamming code is
decoded
Bits 1,3,5,7 bits 2,3,6,7 and bits 4,5,6,7 are
checked
If an error
A three bit binary number is generated out of
the parity checks and error bit is complimented

Received word 1001001
(1,3,5,7)-1001 no error –put 0 in 1’s position
(2,3,6,7)-0001 error –put 1 in 2’s position
(4,5,6,7)-1001 no error –put 0 in 4’s position
Error word is 010(2)
Compliment 2
nd
bit
Correct code is 1101001

Binary Arithmetic Operations (1/6)
ADDITION
Like decimal numbers, two numbers can be
added by adding each pair of digits together
with carry propagation. (11011)2
+ (10011)2
(101110)2
27
10
+ 19
10
----------------
46
10

Binary Arithmetic Operations (2/6)
Digit addition table:BINARY DECIMAL
0 + 0 + 0 = 0 00 + 0 + 0 = 0 0
0 + 1 + 0 = 0 10 + 1 + 0 = 0 1
1 + 0 + 0 = 0 10 + 2 + 0 = 0 2
1 + 1 + 0 = 1 0 …
0 + 0 + 1 = 0 11 + 8 + 0 = 0 9
0 + 1 + 1 = 1 01 + 9 + 0 = 1 0
1 + 0 + 1 = 1 0 …
1 + 1 + 1 = 1 19 + 9 + 1 = 1 9 0
1
1
0

1
Carry
inCarry
out (11011)2
+ (10011)2
(101110)2 1
1
1
1

1 1
0
0
1

0 0
1
0
1

0 0
1
1
0

1 1
0
0
1

0

Binary Arithmetic Operations (3/6)
SUBTRACTION
Two numbers can be subtracted by subtracting
each pair of digits together with borrowing,
where needed. (11001)2
- (10011)2
(00110)2 (627)10
- (537)10
(090)10

Binary Arithmetic Operations (4/6)
Digit subtraction table:BINARY DECIMAL
0 - 0 - 0 = 0 00 - 0 - 0 = 0 0
0 - 1 - 0 = 1 10 - 1 - 0 = 1 9
1 - 0 - 0 = 0 10 - 2 - 0 = 1 8
1 - 1 - 0 = 0 0 …
0 - 0 - 1 = 1 10 - 9 - 1 = 1 0
0 - 1 - 1 = 1 01 - 0 - 1 = 0 0
1 - 0 - 1 = 0 0 …
1 - 1 - 1 = 1 19 - 9 - 1 = 1 9
Borro
w (11001)2
- (10011)2
(00110)2 0
1
1
0

0 0
0
1
1

1 1
0
0
1

1 1
1
0
0

0 0
1
1
0

0 0
0
0
0

0

Binary Arithmetic Operations (5/6)
MULTIPLICATION
To multiply two numbers, take each digit of the multiplier
and multiply it with the multiplicand. This produces a
number of partial productswhich are then added. (11001)2 (214)10Multiplicand
x (10101)2 x (152)10Multiplier
(11001)2 (428)10
(11001)2 (1070)10 Partial
+(11001)2 +(214)10 products
(1000001101)2 (32528)10Result

Negative Numbers Representation
Unsigned numbers: only non-negative values.
Signed numbers: include all values (positive and negative).
Till now, we have only considered how unsigned (non-
negative) numbers can be represented.
There are three common ways of representing signed
numbers
Sign-and-Magnitude
1s Complement
2s Complement

Negative Numbers: Sign-and-Magnitude
(1/4)
Negative numbers are usually written by writing a
minus sign in front.
Example:
-(12)
10, -(1100)
2
In sign-and-magnitude representation, this sign is
usually represented by a bit:
0for +
1for -

Negative Numbers: Sign-and-Magnitude
(2/4)
Example: an 8-bit number can have 1-bit sign
and 7-bit magnitude.
sign
magnitude

Negative Numbers: Sign-and-Magnitude
(3/4)
Largest Positive Number: 0 1111111 +(127)
10
Largest Negative Number: 1 1111111 -(127)
10
Zeroes: 0 0000000 +(0)
10
1 0000000 -(0)
10
Range: -(127)
10to +(127)
10
Question: For an n-bit sign-and-magnitude
representation, what is the range of values that
can be represented?

Negative Numbers:Sign-and-Magnitude
(4/4)
To negate a number, just invert the sign bit.
Examples:
-(0 0100001)
sm = (1 0100001)
sm
-(1 0000101)
sm= (0 0000101)
sm

1s and 2s Complement
Two other ways of representing signed numbers for
binary numbers are:
1s-complement
2s-complement
They are preferred over the simple sign-and-
magnitude representation.

1s Complement (1/2)
Essential technique: invertall the bits.
Examples: 1s complement of (00000001)
1s= (11111110)
1s
1s complement of (01111111)
1s = (10000000)
1s
Largest Positive Number: 0 1111111 +(127)
10
Largest Negative Number: 1 0000000 -(127)
10
Zeroes: 0 0000000
1 1111111
Range: -(127)
10to +(127)
10
The most significant bit still represents the sign:
0 = +ve; 1 = -ve.

1s Complement (2/2)
Examples (assuming 8-bit binary numbers):
(14)
10= (00001110)
2
-(14)
10= -(00001110)
2= (11110001)
1s
-(80)
10= -( ? )
2= ( ? )
1s

1’s compliment subtraction
Represent the number in true binary form
Add 1’s compliment of subtrahend to the minuend
If a carry, bring the carry around and add it to the
LSB
Look at the sign bit , If it is 0 result is positive and in
true binary
If MSB is 1, the result is negative and is in 1’s
compliment form
Take 1’s compliment to get the magnitude in binary

46-14
+14 00001110
-14 11110001
46 00101110
-14 + 11110001
----------------------
+32 1 00100000 Add carry to LSB
Example

2s Complement (2/4)
Essential technique: invertall the bits and add
1.
Examples:
2s complement of
(00000001)
2s= (11111110)
1s(invert)
= (11111111)
2s(add 1)
2s complement of
(01111110)
2s= (10000001)
1s(invert)
= (10000010)
2s(add 1)

2s Complement (3/4)
Largest Positive Number: 0 1111111
+(127)
10
Largest Negative Number: 1 0000000 -(128)
10
(special Case)
Zero: 0 0000000
Range: -(128)
10to +(127)
10
The most significant bit still represents the sign:
 0 = +ve; 1 = -ve.

2s Complement (4/4)
Examples (assuming 8-bit binary numbers):
(14)
10= (00001110)
2
-(14)
10= -(00001110)
2= (11110010)
2s
-(80)
10= -( ? )
2= ( ? )
2s

2’ compliment subtraction
Add the 2’s compliment of subtrahend to the
minuend
If there is a carry ignore it
If MSB is 0, result is positive and in true binary
form
If MSB is a 1 result is negative and is in 2’s
compliment form
Take 2’s compliment

Example
46-14
+1400001110
-1411110010
+46 00101110
-14 +11110010
----------------------
+32 100100000(Ignore carry)