Definition of one’s complement
v The ones' complement
of a binary number is defined as the value obtained by inverting all the bits
in the binary representation of the number (swapping 0's for 1's and
vice-versa).
v In this form, a
negative number is the 1’s complement of the corresponding positive number.
v The 1’s complement of
a binary number is found by changing all 1s to 0s and all 0s to 1s as shown
below:
+2810
= 000111002
-2810 = 111000112
(1’s complement of +25)
Definition
of two’s complement
v
Two's complement is a mathematical
operation on binary numbers, as well as a representation of signed binary
numbers based on this operation. The two's complement of an N-bit number is
defined as the complement with respect to 2N, in other words the
result of subtracting the number from 2N.
v
The 2’s complement of a binary number
can be obtained by adding 1 to one’s complement:
2’s complement = (1’s complement) + 1
Example:
The
negative (-) decimal number conversion is done in next steps .Lets we convert -118.
Step 1: Separate the sign and magnitude number
of -1 .If the sign bits is 1, its represent as negative sign in the 2s complement
conversion.
Step 2: Convert the decimal number to its
7-bits binary equivalent.
Decimal
|
8-bits binary number
|
|
Note
|
|
sign
|
Magnitude
|
|
|
118
|
0
|
1110110
|
Convert to 7-bits binary
|
|
|
|
0001001
|
1st complement
|
Each 0 is changed to 1 and each 1 to 0.
|
|
|
0001010
|
2nd
|
|
|
|
|
|
|
Another Example:
Express
the decimal number -55 as an 8-bit in the sign-magnitude, 1’s complement, and
2’s complement forms.
SOLUTION:
8-bit number for + 5510 =
001101112
Sign-magnitude form for -5510
= 101101112
Ø Change the sign bit to a 1 and leave
the magnitude bits as they are 1’s complement form for -5510 =
110010002
Ø
Take the 1’s complement of +55 by
changing all 1’s to 0s and 0s to 1s
2’s
complement form for -5510 =
11001000 1's complement
+ 1
11001001 2's complement
2’s Complement Operations
1410 000011102
+ 2510 --------> + 000110012
3910 001001112
Positive Number and Smaller Negative Number
2910
- 1510
SOLUTION:
Step 1 : Find the binary numbers for 2910
2910 = 000111012
Step 2: Find the binary form for -1510 using 2's complement
-1510 = 111100012
Step 3 : Add the binary numbers
000111012
+ 111 100012
1000011102
|
|
|
Discard carry over
Positive Number and Larger Negative
Number
1210
- 2510
Tasks:
1. Find the binary form
for 1210
2. Find the binary form
for −2510 using 2’s complement
3. Add the binary numbers
Solution:
Step 1 :+122 --------> 000011002
Step 2 :
+2510 ------> 000110012
-2510 ------> 111001102
+ 1
111001112
Step 3 :
1210 000011002
+( -2510) --------> + 111001102
111100112= -1310
Check the answer using 2's complement
111100112 --------> 000011002
+ 1
000011012 = +1310
Written by EOH WENG JIAN(B031210151)
it's easy to understand...thank u for your effort
ReplyDelete