Upload
socmaster
View
215
Download
0
Embed Size (px)
Citation preview
8/13/2019 NUMERICAL CODING SYSTEMS
http://slidepdf.com/reader/full/numerical-coding-systems 1/5
NUMERICAL CODING SYSTEMS
_______________________________________________________________________________________________S.KLIMIS Computer Science Page 1/5
NUMERICAL CODING SYSTEMS
The numerical Coding Systems are used to represent numbers in a computer. Basically they are
engineered in order to be capable of representing negative numbers in binary format.
1. SMC : Sign and Magnitude Code
The most significant bit (MSB) has no place value; it represents the sign, i.e. 0 for a positive number
and 1 for a negative number. A 7-bit TCC register has the following place values:
S 32 16 8 4 2 1
* * * * * * *
Range of Values that can be stored in a SMC register : -(2n-1
-1) to 2n-1
-1 ,
Where n is the number of bits.
Negation(change of sign) : Change the first bit, 1 for 0 or 0 for 1.
Exampl es:001010010 becomes 1010100101100110 becomes 0100110
2. TCC : Two’s 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 : -2n-1
to 2n-1
-1
Where n is the number of bits.
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
8/13/2019 NUMERICAL CODING SYSTEMS
http://slidepdf.com/reader/full/numerical-coding-systems 2/5
NUMERICAL CODING SYSTEMS
_______________________________________________________________________________________________S.KLIMIS Computer Science Page 2/5
3. OCC : One’s Complement Code
The most significant bit (MSB) has the expected place value reduced by 1, with a minus sign, i.e. a 7-
bit TCC register has the following place values:
-63 32 16 8 4 2 1
* * * * * * *
Range of Values that can be stored in a OCC register : -(2n-1
-1) to 2n-1
-1
Where n is the number of bits.
Negation(change of sign) : Change all the 1s for 0s and the 0s for 1s.
Exampl es:001010010 becomes 110101101
101010000 becomes 010101111
Exercises:
(a) Place -4510 into 7-bit TCC
(b) Place -83 into 8-bit OCC register
(c) Place 10010000tcc into 10 bit SMC
(d) Place -3758 into 10 bit TCC
(e) Show how -3E16 is represented into 10-bit TCC
(f) Place 11110000occ into 9 bit TCC
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- bi t TCC
- 64 32 16 8 4 2 1* * * * * * *0 1 0 1 1 0 1
NEGATE
1
1
0
0
1
1
0 0
0 0
1 1
01+1
( b) Take 4545 10110110
8- bi t OCC2
- 128 64 32 16 8 4 2 1* * * * * * * *0 1 0 1 0 0 1 1
NEGATE 1 0 1 0 1 1 0 0
8/13/2019 NUMERICAL CODING SYSTEMS
http://slidepdf.com/reader/full/numerical-coding-systems 3/5
NUMERICAL CODING SYSTEMS
_______________________________________________________________________________________________S.KLIMIS Computer Science Page 3/5
(c) 10010000tcc is a negative number (first bit 1). To obtain the positive negate:
01101111
1+
-----------------
01110000
10-bit SMC
S 256 128 64 32 16 8 4 2 1
* * * * * * * * * *
0 0 0 1 1 1 0 0 0 0
NEGATE 1 0 0 1 1 1 0 0 0 0
(d) Take 3758 0111111012
10-bit TCC
-512 256 128 64 32 16 8 4 2 1* * * * * * * * * *
0 0 1 1 1 1 1 1 0 1
NEGATE
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
1+
1
(e) Take 3E16 001111102
10-bit TCC-512 256 128 64 32 16 8 4 2 1
* * * * * * * * * *
0 0 0 0 1 1 1 1 1 0
NEGATE
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
1
1
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
NEGATE
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
1+
1
8/13/2019 NUMERICAL CODING SYSTEMS
http://slidepdf.com/reader/full/numerical-coding-systems 4/5
NUMERICAL CODING SYSTEMS
_______________________________________________________________________________________________S.KLIMIS Computer Science Page 4/5
PERFORMING ARITHMETIC OPERATIONS
Actually the only arithmetic operation that the computer performs is addition. The subtraction operation 32-45 is actually
an addition 32+(-45). Similarly -32-45 is (-32) + (-45).
Method to simulate addition/subtraction within a given register
• Convert the absolute values of the numbers into the binary system, i.e. ignore the minus sign, if
any
• Place the positive numbers into the register.
• If any original number is negative, negate to change the sign
• Perform the addition
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, 6010 1111002
-64 32 16 8 4 2 1* * * * * * *0 1 0 0 0 0 0 32
0 1 1 1 1 0 0 60+ 1 0 0 0 0 1 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 = carry in 0, Result OK
8/13/2019 NUMERICAL CODING SYSTEMS
http://slidepdf.com/reader/full/numerical-coding-systems 5/5
NUMERICAL CODING SYSTEMS
_______________________________________________________________________________________________S.KLIMIS Computer Science Page 5/5
(b) Perform the operation -2010-1310 in 7-bit TCC
2010 101002, 1310 11012
-64 32 16 8 4 2 1* * * * * * *0 0 1 0 1 0 0 201 1 0 1 0 1 1
1+ Negate to obtain -20---------------------------------1 1 0 1 1 0 0 -20
0 0 0 1 1 0 1 13+ 1 1 1 0 0 1 0
1+ Negate to obtain -13
---------------------------------1 1 1 0 0 1 1 -13
---------------------------------------1 0 1 1 1 1 1 -33
carry out 1 = carry in 1, Result OK
(c) Perform the operation -2010-5010 in 7-bit TCC
2010 10100, 1310 1101
-64 32 16 8 4 2 1* * * * * * *0 0 1 0 1 0 0 201 1 0 1 0 1 1
1+ Negate to obtain -20---------------------------------1 1 0 1 1 0 0 -20
0 1 1 0 0 1 0 50+ 1 0 0 1 1 0 1
1+ Negate to obtain -50---------------------------------1 0 0 1 1 1 0 -50
---------------------------------------0 1 1 1 0 1 0 -33
carry out 1 ≠ carry in 0, Result incorrect OVERFLOW
(d) Perform the operation -2010-1310 in 7-bit OCC
200 10100, 1310 1101-63 32 16 8 4 2 1
* * * * * * *0 0 1 0 1 0 0 20
1 1 0 1 0 1 1 Negate, -20
+0 0 0 1 1 0 1 13
1 1 1 0 0 1 0 Negate, -13---------------------------------------
1 0 1 1 1 0 1 -34
carry out 1 = carry in 1, Result OK but 1 must be added1 0 1 1 1 0 1 -34
1+
--------------------------------
1 0 1 1 1 1 0 -33 OK