Computer Science 324
Computer Architecture

Mount Holyoke College
Fall 2009


Lab 4: Bit Manipulations in C
Due: 1:15 PM, Friday, October 30, 2009



Unix and C practice

  1. Identify the function of and experiment with these Unix Commands:
     
    ls         cd         cp         mv         rm         mkdir      pwd
    man        chmod      cat        more       grep       head       tail
    ln         find       rmdir      wc         diff       tar
    

    Identify the function of and experiment with these Emacs Commands:

     
    C-x C-s    C-x C-c    C-x C-f    C-x C-w    C-g        C-a        C-e        
    C-d        C-_        C-v        M-v        C-s        C-r        M-%
    

    Learn these commands - you will use them often. Hints can be found in the Unix and Emacs web pages on the course website.

  2. Write a "Hello, world!" program in C and run it on a Linux system. The C compiler "gcc" should be available.


C Programming Assignments

The main part of the lab is to write two C programs. Approach these problems as best you can as a computer scientist. If you're having trouble, ask questions! Make sure that your code is well written and documented. I encourage you, will not require you, to develop them using Unix. You are, however, required to make sure your programs run properly on the CS Lab Linux systems in Clapp 202.

  1. Write a C program prime.c that reads an integer from the input or command line (your choice, do both for a point of extra credit) and prints out whether the number itself is prime, then prints the primes that are closest to it (next smaller and next larger). You might use this in a data structures course if you're looking to find an appropriate size for a hash table. Note that there no primes less than 2. To earn full credit, you should maximize efficiency by not checking for unnecessary factors and you should avoid making expensive calls to the math library (such as sqrt(3)).
  2. A certain security system includes a keypad where access codes are entered as 5 digit numbers. On this particular system, 1 and 2 are on the same button, as are 3 and 4, etc. 9 and 0 are on the same button as well.

    Write a C program access.c that reads in a five digit access code as a decimal number that writes out each of the five digit access codes that are equivalent (there are 32). Make sure that you print any leading zeros. Again, your program may prompt for the input value or accept it on the command line. You may assume that the value on the input is an integer.

Submit your programs as attachments via electronic mail to jteresco AT mtholyoke.edu.

Your programs will be graded based on correctness, documentation, structure, and performance.