Quiz 2(a) Tue 2 Sep 2008

  1. Write the binary number 1001110010 in hexadecimal notation. Show your work.

    Answer:

              10 0111 0010 = 2 7 2 in hexadecimal
    because
              0010 = 2
              0111 = 7
    
  2. Write the decimal number 321 as a bit sequence, i.e.: in binary notation.
    1. Execute the algorithm by hand and show all steps.

      Answer:

              n    n / 2    n % 2
           ----------------------------
             321    160       1
             160     80       0
              80     40       0
              40     20       0
              20     10       0
              10      5       0
               5      2       1
               2      1       0
               1      0       1
      
      So 321 in binary is 101000001 = 1 0101 0001
      
    2. Show how to use the hexadecimal conversion in Python to verify your answer.

      Answer:

      >>> '%X' % 321
      '141'