CS 451/LLC Lab 3: Processing positional notation

Due Wed 22 Jan 2006

  1. Write a function which takes a list of Booleans and returns an integer, corresponding to the value represented by the list when considered as a binary numeral (False is 0, True is 1),

    So [True, True, False] should "evaluate" to 6.

  2. Consider the following data type for representing bits:
    data Bit = Zero | One deriving (Eq, Ord, Enum, Show)
    Re-write the above functions to work with lists of bits rather than lists of Booleans; re-use as much code as you can, and abstract where possible.

  3. Write a function which represents integers as binary numerals; return a String so that (for example) 25 is sent to either "11001".

  4. Write a function which takes two lists of Booleans (or Bits, your choice) and returns a list (same type) representing their sum. (You should actually handle the cases directly, i.e., you should not just convert the lists to integers, add them, and convert back again).

  5. Write two functions which convert back and forth between numbers (Haskell Ints) and Strings in base 10. Re-use as much code as possible from above: abstract!