Java Primitive Data Types and Base Conversion

  1. Use repeated division/multiplication by 8 and a binary 3-digit lookup to convert the following numbers by hand, to binary, then to hexadecimal.
    1. 88
      8| 88 Remainders 1308
      8| 11 0. 001 011 0002
      8|  1 3 0101 1000
            0 1 5816

       

    2. 132
      8| 132 Remainders 2048
      8| 16 4. 010 000 1002
      8|  2 0 1000 0100
           0 2 8416

       

    3. 132.456
      13210 = 2048   204.3518
      8 x 0.456 = 3.648 0.45610 » 0.3518 010 000 100.011 101 0012
      8 x 0.648 = 5.184 3    1000 0100.0111 0100 1000
      8 x 0.184 = 1.472 1 84.74816

       

    4. 103
      8| 103 Remainders 1478
      8|  12 7. 001 100 1112
      8|    1 4 0110 0111
            0 1 6716

       

    5. 10.1
      8| 10 Remainders 12.0638
      8|   1 2. 001 010.000 110 0112
           0 1      1010.0001 1001 1000
      8 x 0.1 = 0.8, 8 x 0.8 = 6.4,
      8 x 0.4 = 3.2
      0.063 A.19816

       

  2. Convert the following binary number s to decimal, hex, and octal. Then convert each octal and hex number back to decimal.
    1. 1010.0001100110011
      (23 + 21) . (2-4 + 2-5 + 2-8 + 2-9 + 2-12 + 2-13) = 10.099975585938
      1 010.000 110 011 001 1 = 12.063148
      1010.0001 1001 1001 1 = A.199816
      12.063148 = (81 + 2
      ×80) . (6×8-2 + 3×8-3 + 8-4 + 4×8-5) = 10.099975585938
      A.199816 = (10
      ×160) . (16-1 + 9×16-2 + 9×16-3 + 8×16-4) = 10.099975585938
    2. 1000011
      26 + 21 + 2= 67
      001 000 011 = 1038 =
      82 + 3×80 = 67
      0100 0011 = 4316 = 4×161 + 3×160 = 67
    3. 10110000.001101001011
      27 + 25 + 24 + 2-3 + 2-4 + 2-6 + 2-9 + 2-11 + 2-12 = 176.205810547
      010 110 000.001 101 001 011 = 260.15138 = 2×82 + 6×81 + 8-1 + 5×8-2 + 8-3 + 3×8-4 = 176.205810547

      1011 0000.0011 0100 1011 = B0.34B16 = 11×161 + 3×16-1 + 4×16-2 + 11×16-3 = 176.205810547
    4. 1001001
      26 + 23 + 20 = 73
      001 001 001 = 1118 = 82 + 81 + 80 = 73
      0100 1001 = 4916 =
      4×161 + 9×160 = 73
  3. Write the following numbers as Java bytes then convert the Java bytes to hexadecimal.
    1. 123
      8| 123 Remainders 1738
      8|  15 3. 001 111 0112
      8|    1 7 0111 1011
            0 1 7B16

       

    2. -123
      -(0111 1011) = 1000 0101 = 8516
    3. 8
      108 = 001 000 = 0000 1000 = 816
    4. -8
      -(0000 1000) = 1111 1000 = F816
  4. Write the following as Java integers, convert the Java word to hexadecimal.
    1. 129
      0000 0000 0000 0000 0000 0000 1000 0001
      0000008116

    2. -129
      1111 1111 1111 1111 1111 1111 0111 1111
      FFFFFF7F16

    3. 12,500
      0000 0000 0000 0000 0011 0000 1101 0100
      0000030D4

    4. -12,500
      1111 1111 1111 1111 1100 1111 0010 1100
      FFFFCF2C16