Académique Documents
Professionnel Documents
Culture Documents
-(2n-1-1) to 2n-1-1 ,
Examples:
001010010 becomes 101010010
1100110
becomes 0100110
2. TCC: Twos Complement Code
The most significant bit (MSB) has the expected place value with a minus sign, i.e. a 7-bit TCC
register has the following place values:
-64 32 16 8 4 2 1
* * * * * * *
Range of Values that can be stored in a TCC register :
Where n is the number of bits.
-2n-1 to 2n-1-1
Negation(change of sign) : Change all the 1s for 0s and the 0s for 1s. Add 1 to the result.
Examples:
001010010 becomes 110101101 110101101
+1
------------110101110
101010000 becomes 010101111 010101111
+1
------------010110000
_______________________________________________________________________________________________
S.KLIMIS
Computer Science
Page 1/5
-(2n-1-1) to 2n-1-1
Negation(change of sign) : Change all the 1s for 0s and the 0s for 1s.
Examples:
001010010 becomes 110101101
101010000 becomes 010101111
Exercises:
(a)
(b)
(c)
(d)
(e)
(f)
Method
If the original number is positive take the positive number, otherwise leave it as is.
Convert the number to the binary system, if not already
Place the number into the given register (right justified), fill remaining leading bits with 0s
Negate in the new register if the original number was negative
Solutions
(a) Take 45
4510 1011012
7-bit
-64 32 16
*
*
*
0
1
0
1
0
1
NEGATE
TCC
8 4
* *
1 1
0 0
1
*
1
0
1+
0 0 1 1
(b) Take 45
4510 1011012
8-bit OCC
-128 64 32 16
*
*
*
*
0
1
0
1
NEGATE
1
0
1
0
8
*
0
1
2
*
0
1
4
*
0
1
2
*
1
0
1
*
1
0
_______________________________________________________________________________________________
S.KLIMIS
Computer Science
Page 2/5
(c) 10010000tcc is a negative number (first bit 1). To obtain the positive negate:
01101111
1+
----------------01110000
10-bit SMC
128 64 32
*
* *
0
1 1
0
1 1
16
*
1
1
8
*
0
0
4
*
0
0
2
*
0
0
0111111012
10-bit TCC
-512 256 128 64 32
*
*
*
* *
0
0
1
1 1
0 0
0
1
1
16
*
1
0
8
*
1
0
4
*
1
0
2
*
0
1
8
*
1
0
4
*
1
0
2
*
1
0
S
*
0
1
NEGATE
256
*
0
0
1
*
0
0
NEGATE
1
1
*
1
0
1+
0 0 1 1
001111102
-512
*
0
1
256
*
0
1
10-bit
128 64
*
*
0
0
1
1
TCC
32 16
* *
1 1
0 0
NEGATE
1
1
*
0
1
1+
0 0 1 0
(f) 11110000occ is a negative number (first bit 1). To obtain the positive negate:
00001111
9-bit TCC
-256 128 64 32 16 8 4 2 1
*
*
* * * * * * *
0
0
0 0 0 1 1 1 1
1 1 1 0 0 0 0
1
1
1+
NEGATE
1 1 1 0 0 0 1
1
1
_______________________________________________________________________________________________
S.KLIMIS
Computer Science
Page 3/5
OVERFLOW CHECKING
While adding two binary numbers always check the carry-in and the carry-out.
The carry-in is the carry inserted into the first bits of the operation (the so called MSBs=most
significant bits)
The carry-out is the carry that remains after the addition of the first bits of the operation (MSB)
IF THE CARRY OUT IS NOT THE SAME AS THE CARRY IN THEN WE HAVE AN OVERFLOW,
THEREFORE THE RESULT IS INCORRECT.
If the operation is carried out in a TCC registered the carry-out is always ignored.
If the operation is taking place in an OCC registered and the carry-out is 1, then it must be taken to
the other side and added on, in order to obtain the correct result.
EXAMPLES
(a) Perform the operation 3210-6010 in 7-bit TCC
3210 1000002,
-64
*
0
0
1
6010 1111002
32
*
1
1
0
1
*
0
32
0
60
1
1+
Negate to obtain -60
--------------------------------1 0 0 0 1 0 0
-60
--------------------------------------1 1 0 0 1 0 0
-28
carry out 0
16
*
0
1
0
8
*
0
1
0
4
*
0
1
0
2
*
0
0
1
= carry in 0,
Result OK
_______________________________________________________________________________________________
S.KLIMIS
Computer Science
Page 4/5
32
*
0
1
1
*
0
1
1+
--------------------------------1 1 0 1 1 0 0
0 0
1 1
16
*
1
0
carry out 1
1
0
4
*
1
0
1
0
2
*
0
1
20
Negate to obtain -20
-20
1
13
0
1+
Negate to obtain -13
--------------------------------1 1 1 0 0 1 1
-13
--------------------------------------1 0 1 1 1 1 1
-33
0
1
8
*
0
1
0
1
= carry in 1, Result OK
32
*
0
1
1
*
0
1
1+
--------------------------------1 1 0 1 1 0 0
0 1
1 0
16
*
1
0
0
1
4
*
1
0
0
1
2
*
0
1
20
Negate to obtain -20
-20
0
50
1
1+
Negate to obtain -50
--------------------------------1 0 0 1 1 1 0
-50
--------------------------------------0 1 1 1 0 1 0
-33
1
0
8
*
0
1
1
0
32
*
0
1
16
*
1
0
8
*
0
1
4
*
1
0
2
*
0
1
1
*
0
1
20
Negate, -20
+
0 0 0 1 1 0 1
1 1 1 0 0 1 0
--------------------------------------1 0 1 1 1 0 1
carry out 1
= carry in 1,
1
13
Negate, -13
-34
1
1+
-------------------------------1 0 1 1 1 1 0
-34
-33 OK
_______________________________________________________________________________________________
S.KLIMIS
Computer Science
Page 5/5