Homework Assignment #2

Solutions

  1. If a file is of the length 543246540422 bits, show the file length in the unit of byte, using prefix kilo, mega, giga, and tera , separately. (Up to three digits after the decimal point)

    543246540422 bits = 543246540422/8 bytes ≈ 67905817553 bytes ≈ 67905817.553 kilo bytes ≈ 67905.818 mega bytes ≈ 67.906 giga bytes ≈ 0.066 tera bytes.

  2. If the execution time of a program is 0.0008723459304 second, write this execution in terms of millisecond, microsecond, and nanosecond, separately. (Up to three digits after the decimal point)
    0.0008723459304 second = 0.8723459304 millisecond = 872.3459304 microseconds = 872345.9304 nanoseconds.

  3. Convert 503710 and -438210 to binary, octal and hexadecimal numbers using 16-bit two's complement representation. Show 5037-4382 using binary arithmetic operation. Show conversion and calculation steps.

    (d=5037, b=NULL) (d=4382, b=NULL)
    5037 ÷ 2 = 2518 ...... 1 (d=2518, b=1) 4382 ÷ 2 = 2191 ...... 0 (d=2191, b=0)
    2518 ÷ 2 = 1259 ...... 0 (d=1259, b=01) 2191 ÷ 2 = 1095 ...... 1 (d=1095, b=10)
    1295 ÷ 2 =   629 ...... 1 (d=629,   b=101) 1095 ÷ 2 =   547 ...... 1 (d=547,   b=110)
    629 ÷ 2   =   314 ...... 1 (d=314,   b=1101) 547 ÷ 2   =   273 ...... 1 (d=273,   b=1110)
    314 ÷ 2   =   157 ...... 0 (d=157,   b=01101) 273 ÷ 2   =   136 ...... 1 (d=136,   b=11110)
    157 ÷ 2   =     78 ...... 1 (d=78,     b=101101) 136 ÷ 2   =     68 ...... 0 (d=68,     b=011110)
    78 ÷ 2     =     39 ...... 0 (d=39,     b=0101101) 68 ÷ 2     =     34 ...... 0 (d=34,     b=0011110)
    39 ÷ 2     =     19 ...... 1 (d=19,     b=10101101) 34 ÷ 2     =     17 ...... 0 (d=17,     b=00011110)
    19 ÷ 2     =       9 ...... 1 (d=9,       b=110101101) 17 ÷ 2     =       8 ...... 1 (d=8,       b=100011110)
    9 ÷ 2       =       4 ...... 1 (d=4,       b=1110101101) 8 ÷ 2       =       4 ...... 0 (d=4,       b=0100011110)
    4 ÷ 2       =       2 ...... 0 (d=2,       b=01110101101) 4 ÷ 2       =       2 ...... 0 (d=2,       b=00100011110)
    2 ÷ 2       =       1 ...... 0 (d=1,       b=001110101101) 2 ÷ 2       =       1 ...... 0 (d=1,       b=000100011110)

    Hence, 503710 = 10011101011012, 438210 = 10001000111102, and –438210 = 0001 0001 0001 11102+12 = 1110 1110 1110 0001 + 1 = 1110 1110 1110 0010. Using binary arithmetic.

    carry    1 1 1 1 1 1 1 1 1 1 1            
    0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1
    + 1 1 1 0 1 1 1 0 1 1 1 0 0 0 1 0
    0 0 0 0 0 0 1 0 1 0 0 0 1 1 1 1

    The rseult is 5037V4382 = 5037+(–4382) = 0001 0011 1010 11012 + 1110 1110  1110 00102 = 0000 0010 1000 11112 = 28F16 = 655.

  4. Convert the following binary/octal/hexadecimal numerals to decimal numerals: (a) 101010011101012, (b) 267438, (c) BD039A16.

    (a) 10 1010 0111 01012 = 1×213+1×211+1×29+1×26+1×25+1×24+1×22+1×20 = 8192+2048+512+64+32+16+4+1 = 10869
    (b) 267432 = 2×84+6×83+7×82+4×81+3×80=8192+3072+448+32+3=11747
    (c) BD039A16 = 11×165+13×164+3×162+9×161+10×160 = 11534336+851968+768+144+10 = 12387226
  5. Convert 2703.62510 to IEEE 754 32-bit single precision floating-point format. Show conversion steps.

    2703.62510  = 101010001111.1012 = 1.010 1000 1111 101 x 211 =1.010 1000 1111 1012 x 2138-127

    s=0, e=11+127=138=100010102, f=01010001111101000000000,

    The IEEE 754 representation of floating-point number 2703.62510  is written as 0 10001010 010 1000 1111 1010 0000 0000.

  6. Show the calculation of (a) 1268´3048, (b) 4E5916+8D0A16-A58A16.


    (a) 1 2 6 (b) 4 E 5 9
    × 3 0 4 + 8 D 0 A
    5 3 0 D B 6 3
    0 0 0 A 5 8 A
    4 0 2 3 5 D 9

     (hexadecimal) 

    4 0 7 3 0  (octal) 

  7. Explain what is an escape sequence. Write the following texts in boldface courier font as a C string constant with escape sequences.

    (a)

    Are you going to the movie?
    Yes, it's still early.
    (Note, the strings will be printed in two separate lines.)

    (b)

    'A'%"123"xyz

    (c)

    Who's book is this?      It's Bob's book, isn't?
    (Note, there is a tab character following the question mark.)

    (d)

    \!@#$%^&*()[]{}|_+"',.?/

    (a)

    Are you going to the moive\?\nYes, it\s still early.

    (b)

    "\'A\'\%\"123\"xyz"

    (c)

    "Who\'s book is this\?\tIt\'s Bob\'s book, isn\'t\?"

    (d)

    "\\!@#$\%^&*()[]{}|_+\"\',.\?/"