Software development: bit manipulation package
Implementation at the word or byte level.
We could use the basic primitives of C, but perhaps we want to manipulate very long sequences of (thousands of) bits?
In this case we would need a bitstring datatype. That is, a set of objects and some basic operations on those objects that capture our notion of a string of bits.
In other words an Abstract Data Type
So let's begin by asking ourselves: what is a bitstring?
A bitstring is a sequence of 1' and 0's
How long is the sequence?
For example (left to right, or right to left)
0 1 2 3 ... 31 versus 31 30 ... 3 2 1 0
What operations do we require at a minimum?
Let's begin with a simple implementation based on an example handout.
From the Makefile we see
0. all :: driver :: not important here, for duplicate entries
1. %.o : %.c default processing of .c files
2. depend : use make -n instead
3. bits.o driver.o : multiple objects are OK
4. note make -n and use of touch
From the source code we see
5. typedef unsigned int bits
This is how you define your own variable type "bits"
6. macro definition, here looks like a procedure call, but don't be fooled, this is just a constant of 16 or 32
7. extern ... this header refers to a library function or other independently compiled function.
8. macro definition, beware (x) is not a parameter we are doing type conversion from int to "bits".
9. void main (void); would be enough here, since in this program there are no parameters
10. bits x note use of shorthand of bits for unsigned int
11. print outputs characters and waits for input
12. scanf ("%", &x_in); again note &x_in
13. this is x = (x_in) type conversion only
14. x_comp = x when will this not work?
15. bits_length (x) this is an int