Homework 1

22C:18, Fall 1996

Due Tuesday Sep. 3, 1996, in discussion

Douglas W. Jones

This assignment begins with 2 review questions that are not as much specific to the material in this course as they are to material you should have learned in prior courses or work experience. The final 3 questions focus on material central to success in the remainder of this course!

  1. Part A: Write, in legal Pascal or C, the declarations necessary to declare a binary tree where each node contains a single character called ch.

    Part B: Write, in legal Pascal or C, the declarations of a recursive function that will count the nodes in a tree when given, as a parameter, a pointer to the root node of that tree.

  2. Write, in legal Pascal or C, function that takes, as parameters, a number base (an integer from 0 to 35) and the textual representation of a positive integer written in that base (a blank or null terminated character string) and returns that number as an integer. Obviously, the set of digits must be extended beyond the normal 0 to 9 to handle this! Use upper case letters as extended digits, so that the digit A has the value 10, the digit B has the value 11, etc.

    Don't treat this as a machine problem; you may test your code, but a handwritten submission is good enough, so long as you are confident of its function.

  3. Convert the following numbers to base 10:

    From base 5: 44 444
    From base 8: 44 444
    From base 16: A DAD FEED From base 35: IOWA

  4. Convert the numbers 10, 100 and 1000 from base 10 to:

    Base 5
    Base 8
    Base 16

  5. Convert the following numbers from base 16 to base 2 and then to base 8:

    F0E1D2C3
    B4A59687