I am using this code
int get_bit(int n, int bitnr) {
int mask = 1 << bitnr;
int masked_n = n & mask;
int thebit = masked_n >> bitnr;
return thebit;
}
void printbits(uint32_t bits) {
int i;
for (i = 0; i < 32; i++)
printf("%d", get_bit(bits, i));
printf("\n");
}
to get and print the bits of a uint32_t, and in another function this code
uint32_t bits= 0;
bits|= 1<< 0;
to change the most significant bit (left-most) from 0 to 1.
the problem is when printing bits using the printbits function, it prints them right, but when using printf("%#x", bits);
I'm getting the hex value of the bits as if they are read from right to left!
so the printbits gives me '10000000000000000000000000000000' but the hex value printed is the value of '00000000000000000000000000000001'.
Help appreciated