ECE 2110: Introduction to DigitalSystems
Signed Number Conversions
2
Previous class Summary
Signed-magnitude, two’s complement,one’s complement
Different for negatives numbers
Representations of positive numbers areSAME.
0 may have different representations.
Sign bit: 0 for positive, 1 for negative
3
Signed Decimal to Hex conversion
Step 1:  Know what format you are converting to!!! You mustknow if you are converting the signed decimal to SM, 1scomplement, or 2s complement.   Convert +34, -20  to all three formats.
Step 2:  Ignore the sign, convert the magnitude to binary.    34   =   2 x 16 + 2 =     2216 =   001000102     20   =  1 x 16  + 4 =    1416  =  000101002
Step 3 (positive decimal number):  If the decimal number waspositive, then you are finished no matter what the format is! +34   as an 8 bit SM number is                      2216 =   001000102 +34   as an 8 bit 1s complement number is    2216 =  001000102 +34   as an 8 bit 2s complement number is    2216 =  001000102
4
Signed Decimal to Hex conversion (cont)
Step 3 (negative decimal number):   Need to do more if decimalnumber was negative.  If converting to SM format,   set Sign bit to One:   20  = 000101002, then -20  =>   100101002 = 9416If converting to 1s complement,  complement each bit.   20  = 000101002, then -20 =>   111010112 = EB16If converting to 2s complement, complement and add one.   20  = 000101002 , then -20=> 111010112 + 1 = 111011002 = EC16
5
Signed Decimal to Hex conversion (cont)
Final results:
Compare! +34   as an 8 bit SM number is                      2216 =   001000102 +34   as an 8 bit 1s complement number is    2216 =   001000102 +34   as an 8 bit 2s complement number is    2216 =   001000102
 -20   as an 8 bit SM number is                      9416 =   100101002 -20   as an 8 bit 1s complement number is    EB16 =  111010112 -20   as an 8 bit 2s complement number is    EC16 =  111011002
6
Sign extension?
Pad with 0s for positive numbers and 1sfor negative numbers
7
A common Question?
Given a hex number, how do I know if it is in 2’s complement or1’s complement; is it already in 2’s complement or do I have putit in 2’s complement,   etc.
8
Answer: We cant!
If I write a HEX number,  I will ask for a decimalrepresentation if you INTERPRET the encoding as aparticular method (i.e, either 2’s complement, 1’scomplement, signed magnitude).
A Hex or binary number BY ITSELF can representANYTHING (unsigned number, signed number, charactercode, etc).  You MUST HAVE additional information thattells you what the encoding of the bits mean.
For example: FE16  or   111111102
9
Example Conversions
FE16 as an 8 bit unsigned integer  =     254FE16 as an 8 bit signed magnitude integer =   -126FE16 as an 8 bit ones complement integer  =  - 1FE16 as an 8 bit twos complement integer  =  -27F16 as an 8 bit unsigned integer =    1277F16 as an 8 bit signed magnitude integer  = +1277F16 as an 8 bit ones complement integer = +1277F16 as an 8 bit twos complement integer  = +127To do hex to signed decimal conversion, we need todetermine sign (Step 1), determine Magnitude (step 2),combine sign and magnitude (Step 3)
10
Hex to Signed Decimal Conversion Rules
Given a Hex number, and you are told to convert to a signed integer(either as signed magnitude, 1s complement, 2s complement)
STEP 1:  Determine the sign!  If the Most Significant Bit iszero, the sign is positive.  If the MSB is one, the sign isnegative.  This is true for ALL THREE representations: SM, 1scomplement, 2s complement.  F016   =    111100002    (MSB is ‘1’),  so sign of result is ‘-’  6416   =    011001002   (MSB is ‘0’),  so sign of result is ‘+’.
If the Most Significant Hex Digit is  > 7, then MSB = ‘1’  !!!(e.g., 8,9,A,B,C,D,E,F   =>    MSB = ‘1’ !!!)
11
Hex to Signed Decimal  (cont)
STEP 2  (positive sign):  If the sign is POSITIVE,  then justconvert the hex value to decimal.  The representation is thesame for SM, 1s complement, 2s complement.   6416   is a positive number,  decimal value is          6 x 16 + 4 =    100.
STEP 3 :  Just combine the sign and magnitude to get the result. 6416 as an 8 bit signed magnitude integer  = +1006416 as an 8 bit ones complement integer = +1006416 as an 8 bit twos complement integer  = +100
Note: Final answer is  +100   regardless of whether encoding wasSM, 1s complement, or 2s complement.
12
Hex to Signed Decimal  (cont)
STEP 2  (negative sign):  If the sign is Negative,  then need tocompute the magnitude of the number.
 We will use the trick  that  - (-N)  =  + Ni.e.  Take the negative of a negative number will give you the positivenumber. In this case the number will be the magnitude.If the number is SM format,   set Sign bit to Zero:   F016  =  111100002  =>    011100002 = 7016 = 112If the number is 1s complement,  complement each bit.   F016  =  111100002  =>    000011112 = 0F16 = 15If the number is 2s complement, complement and add one.   F016  =  111100002  =>  000011112 + 1 = 000100002 = 1016 = 16
13
Hex to Signed Decimal  (cont)
STEP 3 (also):  Just combine the sign and magnitude to get the result.
   F016   as 8 bit Signed magnitude number is   -112   F016   as 8 bit ones complement number is   -15   F016   as 8 bit twos complement number is   -16
14
Next…
Quiz#1
Signed Addition/Subtraction