Hello
I'm using the following code to print individual bits of an uint32_t variable
uint32_t test = 0b11111111111111111111111111111111; uint8_t size = sizeof(test) << 3; // multiply by 8 uint8_t bit = 0; for (uint8_t i = 0; i < size; i++) { // compute bit bit = (test & (1 << i)) ? 1 : 0; usartSend("%d - %d\n\r", i, bit); // do stuff with the bit }
The problem is that the 16 most significant bits are printed out as 0, so the result of the above code is
0 - 1 . . . 15 - 1 16 - 0 . . . 31 - 0
The same happens if the uint32 is a random number and not just all 1's.
I verified that the variable is actually 4 bytes by printing its sizeof(), and also verified that it matches UINT32_MAX, so the variable is stored correctly in memory.
I confirmed that the code works for 8 and 16 uint variables, the problem occurs exactly after two bytes, so this must be some ignorance of mine regarding the hw architecture, what is it?
Thanks