CS 473

HW 0 - Non-Decimal Arithmetic

Solutions

Converting Unrelated Radixes

Use the division method to convert each of the following numbers from decimal to eight-bit 2's complement hexadecimal numbers (if I were to be obnoxiously pedantic, the phrase "2's complement hexadecimal" would be incorrect. Why? because technically it's 16's complement)

  1. 43
    OldOld/16Old % 16
    43211
    202
    Since the number was positive, we don't need to take the 2's complement; the result is 2b.
  2. -37
    OldOld/16Old % 16
    3725
    202
    This time the number is negative, so we have to take its 2's complement:
    Original:25
    Invert the bits:da
    Add one:db
  3. 193
    OldOld/16Old % 16
    193121
    12012
  4. So we get c1. But notice that this has a sign bit that's 1 -- a negative number! The original number too large to fit in eight-bit, 2's complement. It would have worked as eight bit unsigned though.

For one of the numbers above, the instructions are impossible. Why? The last one, for the reason stated in the problem solution.

Use the multiplication method to convert each of the following numbers from eight-bit 2's complement binary to decimal.

  1. 00110101

    The number is positive, since the sign bit is 0.

    OldBitNew
    011
    213
    606
    12113
    26026
    52153

  2. 11011010

    The number is negative since its sign bit is 1; we have to start by finding its magnitude

    Original:11011010
    Invert the bits:00100101
    Add one:00100110

    Now we can convert to decimal.

    OldBitNew
    011
    202
    404
    819
    18018
    36137

    Since the number is negative, the result is -37.

  3. 0111

    The number is positive, so we don't need to invert it.

    OldBitNew
    011
    213
    617

Even though the last number above isn't technically the word size requested, there's no problem converting it. Why?

We can just 0-extend. If the most significant bit had been a 1, it would have been ambiguous as to whether it should 0-extended or 1-extended; in that case, it would have been a symptom of a typo in the assignment....

Converting Between Related Radices

Convert each of the following numbers from binary to hexadecimal.

  1. 00111001

    39

  2. 11000111

    c7

  3. 001110

    0e

The last number above doesn't have the right number of bits to convert to hexadecimal; again, it doesn't cause us any problem. Why?

We adopt the convention of taking the bits right to left and 0-filling. Note that in a fraction we adopt the opposite convention and go left to right; in fact, the "real" convention is that we work from the binary point out.

Convert each of the following numbers from hexadecimal to binary.

  1. a3f

    1010 0011 1111

  2. 01d

    0000 0001 1101

  3. aaa

    1010 1010 1010

Addition

Perform the following hexadecimal additions. If the operation were performed on an eight-bit microprocessor, what would be the contents of the resulting NZVC condition codes?

1212acac
+12+79+42+ac
248bee58
N:0110
Z:0000
V:0101
C:0001

Multiplication

Perform the following binary multiplications

1001001110101110
x01101101x10101110
10010011 00000000
00000000  10101110 
10010011   10101110  
10010011    10101110   
00000000     00000000    
10010011      10101110     
10010011       00000000      
00000000        10101110       
0011111010010111    0111011001000100

Division

Perform the following binary divisions

  1. 1101111 / 00010110

        101
    00010110)1101111 
    10110
     01011
     00000
      10111
      10110
          1

  2. 1101000 / 110

      10001
    110)1101000 
    110
     001
     000
      010
      000
       100
       000
       1000
        110
         10


Last modified: Fri Sep 3 10:32:41 MDT 2004