Monday, January 30, 2012

Computer Organization - signed bit number (2's complement and Magnitude)


signed number in binary divided into 2 : [Video]
1.Signed Magnitude
2.Two complement


1.Signed Magnitude

Methode :
A10 = i=0Σn-2(2i*ai)  if an-1 = 0
A10 = -i=0Σn-2(2i*ai) if an-1 = 1

Example:
0000 10102 = 1010
1000 10102 = -1010


1.Two complement

Methode :
A10 = i=0Σn-2(2i*ai)                   if A >= 0
A10 = -2n-1*an-1 + i=0Σn-2(2i*ai) if A  <  0

Example:
0000 10102 = 1010
1000 10102 = -2^7 + 10 = -128 + 10 = -11810


Example:

1. Convert -2010 in as Hexadecimal in form two's complement by 8bit size.

pow(2,7) + ? = -20
-128 + ? = -20
>>> -128.64.32.16.8.4.2.1
>>>  1.1.1.0.1.1.0.0
>>> -128+64+32+ 0+8+4+0+0 = 20
>>> 1110 1100 (Bin) = 0xEC ==>> -20 (Dec) = 0xEC

if from example 1 change size of bit to 10 then ==>> -20 (Dec) = 3EC16
if 20bit ==>> -2010 = FFFEC16
if 22bit ==>> -2010 = 3FFFEC16

Totally : if number is negative then when increasing number of bit we just add the maximum of the most significant


No comments:

Post a Comment