Vous êtes sur la page 1sur 5

NUMERICAL CODING SYSTEMS

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 :
Where n is the number of bits.

-(2n-1-1) to 2n-1-1 ,

Negation(change of sign) : Change the first bit, 1 for 0 or 0 for 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

NUMERICAL CODING SYSTEMS

3. OCC: Ones Complement Code


The most significant bit (MSB) has the expected place value reduced by 1, with a minus sign, i.e. a 7bit 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 :
Where n is the number of bits.

-(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)

Place -4510 into 7-bit TCC


Place -83 into 8-bit OCC register
Place 10010000tcc into 10 bit SMC
Place -3758 into 10 bit TCC
Show how -3E16 is represented into 10-bit TCC
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-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

NUMERICAL CODING SYSTEMS

(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

(d) Take 3758

NEGATE
1

(e) Take 3E16

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

NUMERICAL CODING SYSTEMS

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,

-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

NUMERICAL CODING SYSTEMS

(b) Perform the operation -2010-1310 in 7-bit TCC


2010 101002, 1310 11012
-64
*
0
1

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

(c) Perform the operation -2010-5010 in 7-bit TCC


2010 10100, 1310 1101
-64
*
0
1

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

carry out 1 carry in 0, Result incorrect OVERFLOW


(d) Perform the operation -2010-1310 in 7-bit OCC
200 10100, 1310 1101
-63
*
0
1

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

Result OK but 1 must be added


1

1
1+
-------------------------------1 0 1 1 1 1 0

-34
-33 OK

_______________________________________________________________________________________________
S.KLIMIS
Computer Science
Page 5/5

Vous aimerez peut-être aussi