here...i JUST learned how to do this after reading this post because i was a bit intrigued myself.....this may not be correct but it will give you something to think about.
i would like to ask more advanced programmers what they think about this code while i'm at it.
(by the way, cout << a << endl; is the c++ version of
printf("%d\n",a)
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
struct lbit
{
unsigned a:1; //create variable the size of one bit
};
int mask = 1; //...0000 0001
lbit x; //declaration of lbit
int c = 'A'; //in your case, read sizeof(int) from file
//loop sizeof(int) times bits (per byte) number of times
for(int i = 0; i < sizeof(int) * 8; i++)
{
x.a = mask & c; //0001 & 0001 returns 1
//0001 & 0000 returns 0
//since x.a is only 1 bit this will
//truncate the leading bits
//preventing a non-zero value
//caused by higher ordered bits
cout << x.a << endl; //print out 1 or 0
c = c >> 1; //shift every bit in 'c' one bit to the
//right. 0010 >> 1 becomes 0001
}
system("PAUSE");
return 0;
}