Assignment 4 advice

Written by Julie Zelenski

Warmups

Before you dive in, it might help to work through some thought exercises to bring our your inner bitwise ninja. Answering these questions is not required, nor to be submitted. You are encouraged to freely discuss these warmup questions and answers with your peers (in person, on forum) to help everyone reach a solid foundation on the basic concepts before starting.

You also may find it helpful to review the bits/int/float exercises from labs 3 and 4, especially if you left tasks unfinished or feel you still have gaps in your understanding.

General advice on working with bits

Bit comparing

Sudoku

UTF-8

Saturating

Average

Epsilon

Disassemble

Advice on testing

A note on gdb and float/doubles

You can invoke function calls at the gdb prompt and it will make a valiant effort to invoke the function and print its result. This is pretty handy for working more interactively/experimentally. But be warned that the mechanism can be a little squirrely. For example, if the called function takes or returns variables of float/double type, you may get garbled results. The issue has to do with gdb not having access to the complete type information and doing a bit of guessing. You can add a typecast on the function being called (to its proper type, of course) to force the right interpretation. For example:

    (gdb) p fabs(-3.5)
    $1 = 1                                       // huh ??? why is result from fabs so wrong?
    (gdb) p ((double (*)(double))fabs)(-3.5)     // tell gdb fabs takes double, returns double
     $2 = 3.5

Consider this the one exception to the rule that you should never ever cast a function pointer. :-)

Program facts

Rabbit

                      A rabbit
                           bit
                  A little bit
                   An itty-bitty
                    Little bit of beet.
                      Then bit
                        By bit
                        He bit
                                Because he liked the taste of it.
               But when he bit
                     A wee bit more,
               It was more bitter than before.
             "This beet is bitter!"
                        Rabbit cried.
                 "I feel a bit unwell inside!"
               But when he bit
        Another bite, that bit of beet
Seemed quite all right.
                                Besides
When all is said and done,
                    Better bitter beet
                Than none.

                                              -- Mary Ann Hoberman