Binary Representation
Advantages:
Easy to Read
Good representation for positive (Unsigned) numbers
Disadvantages:
Cannot represent negative (Signed) numbers
Sign-Magnitude Representation
Advantages:
Easy to Read
Disadvantages:
Two Representatives for Zero
Using our 4-bit Sign-Magnitude example we have,
+0 = 0000
-0 = 1000
Arithmetic is difficult
Example, lets add Positive 2 to Negative 4, which we expect the answer to be Negative 2.
+2 0010
-4 1100
---- ------
-6 1110
The result is -6, which is not what we expect
Another Example lets add +2 to -2, we expect the answer to be zero
+2 0010
-2 1010
---- -----
1100
The result of -4, which again is not what we expect
Two's Complement Representation
Two's complement is the method computers use to represent Signed numbers.
The most-significant-bit is the sign bit.
0 = positive value
1 = negative value
The negative representation of a number is created by
Start with the positive number
Flip the bits (Change '0' to '1' and '1' to '0')
Add the value 1
Advantages:
One value for Zero.
Conversion from Positve to Negative and Negative to Positive numbers is easy and consistent.
Example:
+ 2 = 0010
Flip the bits = 1101 and add 1 makes 1110 which is -2
-2 = 1110
Flip the bits = 0001 and add 1 makes 0010 which is +2]
Advantages:
Easy to Read
Good representation for positive (Unsigned) numbers
Disadvantages:
Cannot represent negative (Signed) numbers
Sign-Magnitude Representation
Advantages:
Easy to Read
Disadvantages:
Two Representatives for Zero
Using our 4-bit Sign-Magnitude example we have,
+0 = 0000
-0 = 1000
Arithmetic is difficult
Example, lets add Positive 2 to Negative 4, which we expect the answer to be Negative 2.
+2 0010
-4 1100
---- ------
-6 1110
The result is -6, which is not what we expect
Another Example lets add +2 to -2, we expect the answer to be zero
+2 0010
-2 1010
---- -----
1100
The result of -4, which again is not what we expect
Two's Complement Representation
Two's complement is the method computers use to represent Signed numbers.
The most-significant-bit is the sign bit.
0 = positive value
1 = negative value
The negative representation of a number is created by
Start with the positive number
Flip the bits (Change '0' to '1' and '1' to '0')
Add the value 1
Advantages:
One value for Zero.
Conversion from Positve to Negative and Negative to Positive numbers is easy and consistent.
Example:
+ 2 = 0010
Flip the bits = 1101 and add 1 makes 1110 which is -2
-2 = 1110
Flip the bits = 0001 and add 1 makes 0010 which is +2]