Simple program I made when I was experimenting with inttypes.h:
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
bool get_bit(uint32_t x, uint8_t n) {
x >>= n;
return x & 1;
}
int main() {
uint32_t x;
uint8_t n;
printf ("Enter x: ");
scanf("%"SCNu32, &x);
printf ("Enter n: ");
scanf("%"SCNu8, &n);
printf("The %"PRIu8"th bit of %"PRIu32" is: %d", n, x, get_bit(x, n));
return 0;
}
On my phone (64 bit octa core ARN LTE Soc Android 10) it works fine:
Enter x: 1
Enter n: 0
The 0th bit of 1 is: 1
But on my computer (64 bit x86 Windows 10) I get:
Enter x: 1
Enter n: 0
The 0th bit of 0 is: 0
Changing bool to uint8_t doesn't affect it.
EDIT: I tried compiling with MinGW-w64 GCC C99 and C17.