B C (N R) : Inary ODE Egative Epresentation
B C (N R) : Inary ODE Egative Epresentation
SIGN-MAGNITUDE REPRESENTATION
In this representation, the leftmost bit of a binary code represents the sign of the value:
1'S COMPLEMENT
A positive number, N, is represented in the same way as in the Sign and Magnitude representation. For an n-bit number,
1'S COMPLEMENT
A negative number, -N, is represented by the 1's complement of the positive number, N. N' = 1's complement representation for -N. For an n-bit signed binary number,
The leftmost bit (sign bit) = 1 for all negative numbers in the 1's Complement system.
N' = (2n 1) N
5
1'S COMPLEMENT
The 1's Complement representation for -N can also be determined by taking the bit-wise complement of N. N' = 1's Complement representation for -N. For an n-bit signed binary number,
1'S COMPLEMENT
To determine the magnitude of a negative number, -N, that is represented by its 1's Complement, N', simply take the 1's complement of the 1's Complement.
N = (2n 1) N'
positive #
or
SIGN-MAGNITUDE REPRESENTATION
To Compute negative values using Sign/Magnitude (signmag) representation. Begin with the binary representation of the positive value, then flip the leftmost zero bit.
SIGN-MAGNITUDE REPRESENTATION
Ex 1. Find the signmag representation of -610 Step1: find binary representation using 8 bits 610 = 000001102 Step2: if the number is a negative number flip left most bit 10000110 So: -610 = 100001102 form) (in 8-bit sign/magnitude
9
SIGN-MAGNITUDE REPRESENTATION
Ex 2. Find the signmag representation of -3610 Step 1: find binary representation using 8 bits 3610 = 001001002 Step 2: if the number is a negative number flip left most bit 10100100 So: -3610 = 101001002 form) (in 8-bit sign/magnitude
10
SIGN-MAGNITUDE REPRESENTATION
Ex 3. Find the signmag representation of 7010 Step 1: find binary representation using 8 bits 7010 = 010001102 Step 2: if the number is a negative number flip left most bit 01000110 (no flipping, since it is +ve) So: 7010 = 010001102 (in 8-bit sign/magnitude form)
11
SIGN-MAGNITUDE REPRESENTATION
12
13
14
twos
complement
15
So: -610 = 111110102 (in 2's complement form, using any of above methods)
16
00000110 11111010
17
18
(left complemented)
->
01001100 10110100
So: -7610 = 101101002 (in 2's complement form, using any of above methods)
19
20
21
22
23
The result, 1100, is the code for -4, the result of subtracting +7 from +3.
24
addition and subtraction simplified in the twoscomplement system, In 8 bits, -0 has been eliminated, replaced by -128, for which there is no corresponding positive number.
25
2'S COMPLEMENT
A positive number, N, is represented in the same way as in the Sign and Magnitude representation. For an n-bit number,
26
2'S COMPLEMENT
A negative number, -N, is represented by the 2's complement of the positive number, N. N* = 2's complement representation for -N. For an n-bit signed binary number,
The leftmost bit (sign bit) = 1 for all negative numbers in the 2's Complement system. n
N* = (2 ) N
27
2'S COMPLEMENT
Thus, the 2's Complement representation for -N can also be determined by adding 1 to the 1's Complement representation for -N.
N' = 1's Complement representation for -N. N* = 2's Complement representation for -N.
N* = N' + 1
28
2'S COMPLEMENT
To determine the magnitude of a negative number, -N, that is represented by its 2's Complement, N*, simply take the 2's complement of the 2's Complement.
N = (2n) N*
positive #
or
N = (N*)' + 1
bit-wise complement of 2's complement
29
30
QUESTIONS?
31
OVERFLOW
The general rule for detecting overflow when performing 2's Complement or 1's Complement Addition:
An overflow occurs when the addition of two positive numbers results in a negative number. An overflow occurs when the addition of two negative numbers results in a positive number. Overflow cannot occur when adding a positive number to a negative number.
32
BINARY CODES
Weighted Codes
Each position in the code has a specific weight Decimal value of code can be determined Positions of code do not have a specific weight Decimal value assigned to each code
Unweighted Codes
33
BINARY CODES
Code: an-1an-2an-3...a1a0 Weights: wn-1, wn-2, wn-3, ..., w1, w0 Decimal Value: an-1 x wn-1 + an-2 x wn-2 + + a1 x w1 + a0 x w0 Code: a3a2a1a0
34
BINARY CODES
8-4-2-1
4 bits 16 code words Only 10 code words required to represent decimal digits 4 bits 16 code words 4 bits 16 code words
6-3-1-1
35
BINARY CODES
2-out-of-5 Code
Exactly 2 of the 5 bits are 1 for a valid code word. 10 valid code words. Code values for successive decimal digits differ in exactly one bit. 4 bits 16 code words.
Gray Code
36
BINARY CODES
Decimal Digit 0 1 2 3 4 5 6 7 8 9 8-4-2-1 6-3-1-1 Code Code (BCD) 0000 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 0001 0011 0100 0101 0111 1000 1001 1011 1100 Excess-3 2-out-of-5 Code Code 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 00011 00101 00110 01001 01010 01100 10001 10010 10100 11000 Gray Code 0000 0001 0011 0010 0110 1110 1010 1011 1001 1000
37
4-bit binary number used to represent each decimal digit. Weighted code: 8-4-2-1 Binary values 0000 1001 used to represent decimal values 0 9. Binary values 1010 1111 not used. Very different from binary representation.
38
In BCD, each decimal digit is replaced by its binary equivalent value. Example:
Binary:
937.2510 = 1110101001.012
39