Beruflich Dokumente
Kultur Dokumente
Lecture 4
Outlines
➢ Compliments of Numbers
▪ Why Compliments (Comp.)?
▪ 10‘s comp. (or 2‘s comp.) radix (base) comp.
▪ 9‘s comp. (or 1‘s comp.) dimished radix comp.
▪ Subtraction with Comp.
0 1 1 0 1 1 0 = 54
Sum
YES
M≥N
carry is there Using 10’s Compl.,
Discard carry
Subtract
72532 - 3250
Result = M-N
Subtraction With 10’s Complements
➢ Subtraction of two n‐digit unsigned numbers M-N
Sum
NO (M<N)
M≥N
No carry
Using 10’s Compl.,
Take r’s comp. of sum Subtract
Insert a -ive sign
3250 - 72532
Result = M-N
Subtraction With 10’s Complements
➢ Subtraction of two n‐digit unsigned numbers M-N
M + r’s comp. of N
Sum
YES NO (M<N)
M≥N
carry is there No carry
(+3)10 ( 0 0 1 1 )2
(−3)10 ( 1 0 1 1 )2
Sign Magnitude
Signed Magnitude Representation
➢ Left most bit represents sign while the rest of bits
represent the actual number (magnitude)
➢ Convention: Sign bit 0 for +ive and 1 for -ive
➢ User determines if the no. is signed or unsigned
Bin. → Dec.
25
Unsigned
(11001)2
-9
Left bit = 1 (means no. is –ive) Signed
Remaining no. 1001 (means 9)
Signed Magnitude Representation
0 indicating +ive no.
Same as before
(Simple binary)
-9 11110110
1’s Complement
11110111
2‘s Complement Representation
Same as before
(Simple binary)
2’s Complement of
above
Putting Everything Together
Binary Codes
Signed One’s Signed Two’s
Decimal Signed Magnitude
Complement Complement
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-0 1000 1111 –
-1 1001 1110 1111
-2 1010 1101 1110
-3 1011 1100 1101
-4 1100 1011 1100
-5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
31/35
Bits Range
8 -270 (-128) to +27-1 (+127)
16 -215 (-32,768) to +215-1 (32,767)
-231 (-2,147,483,648) to +231-1
32
(+2,147,483,647)
-263 (-9,223,372,036,854,775,808) to
64
+263-1 (9,223,372,036,854,775,807
(185)10
(10111001)2
Warning: Conversion or Coding?
➢ Do NOT mix up conversion of a decimal number
to a binary number with coding a decimal number
with a BINARY CODE
➢ Example:
❑ (13)10 = (1101)2 (This is conversion)
❑ (13)10 0001 0011 (This is coding)
Binary Coded Decimal (BCD) Code
Binary Coded Decimal (BCD) Code
➢ BCD is a weighted code (8421)
➢ Each bit position is assigned a weighting factor
such that each digit can be evaluated by adding
the weights of all 1’s in the coded combination
➢ Example:
(0110)
=6
2421 Weighted Code
➢ Left most bit: weightage of 2
➢ Right most bit: weightage of 1
8, 4, -2, -1 Weighted Code
Excess 3 Code
Binary + 3
Putting All Together
Gray Code
Decimal Binary Gray
00 0000 0000
01 0001 0001
02 0010 2 bit changes 0011
03 0011 0010
04 0100 3 bit changes 0110
05 0101 0111
06 0110 2 bit changes 0101 Only
07 0111 0100 1 bit
08 1000 1100 change
09 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
7
TX RX
Parity bit
Error-Detecting Code
➢ Examples:
7
TX RX
Parity bit
Error-Detecting Code
At the receiver side:
If an even parity is
7
detected, send an ACK
TX RX (Acknowledgement).
Parity bit If error was detected
send negative
Transmit Ha in ASCII acknowledge (NAK)
G2
G1
111 G0
101 010 011
▪ Is this a problem?
Chapter 1 52
Gray Code (Continued)
▪ Is this a problem?
Parity
One bit added to a group of bits to make the total number
of ‘1’s (including the parity bit) even or odd
● Even 1 0 1 1 1 0 1 0 0 0 0 0 1
● Odd 0 0 1 1 1 1 1 0 0 0 0 0 1