/* Driver program to test the bitstring package. */ #include #include "bits.h" int main(int argc, char* argv[]) { int i; /* generic counter */ int x_in; bits x, x_comp; /* read in an int */ printf ("Give me an int:\t"); scanf ("%d", &x_in); /* convert into a bit string */ x = bits_from_int(x_in); /* print the bits of x */ printf ("Size of bits is %d, size of int is %d bytes\n", sizeof(x), sizeof(x_in)); printf ("The %d bits of %d are:\t", bits_length(x), x_in); bits_printf (x); printf ("\n"); /* complement the bits of x */ printf ("The complement bits are:"); x_comp = x; /* does this work always? */ for ( i = 0; i < bits_length(x); i++ ) { /* is not something fishy here? */ x_comp = bits_put(x_comp, i, ~bits_get(x_comp, i)); } bits_printf (x_comp); printf ("\n"); return (1); }