#define INT_BITS_32 32
uint32_t leftRotate_uint32(uint32_t n, uint32_t d) {
return (n << d) | (n >> (INT_BITS_32 - d));
}
void printBinary32(uint32_t value) {
for (int8_t i = 31; i >= 0; i--) Serial.print(bitRead(value, i));
Serial.println();
}
void setup() {
Serial.begin(115200);
uint32_t value = 0b1111111111111111;
for (uint32_t i = 0; i < INT_BITS_32; i++) {
uint32_t rotated = leftRotate_uint32(value, i);
Serial.print("Rotate by ");
if (i < 10) Serial.write(' ');
Serial.print(i);
Serial.print(": ");
printBinary32(rotated);
}
}
void loop() {}
you should see
Rotate by 0: 00000000000000001111111111111111
Rotate by 1: 00000000000000011111111111111110
Rotate by 2: 00000000000000111111111111111100
Rotate by 3: 00000000000001111111111111111000
Rotate by 4: 00000000000011111111111111110000
Rotate by 5: 00000000000111111111111111100000
Rotate by 6: 00000000001111111111111111000000
Rotate by 7: 00000000011111111111111110000000
Rotate by 8: 00000000111111111111111100000000
Rotate by 9: 00000001111111111111111000000000
Rotate by 10: 00000011111111111111110000000000
Rotate by 11: 00000111111111111111100000000000
Rotate by 12: 00001111111111111111000000000000
Rotate by 13: 00011111111111111110000000000000
Rotate by 14: 00111111111111111100000000000000
Rotate by 15: 01111111111111111000000000000000
Rotate by 16: 11111111111111110000000000000000
Rotate by 17: 11111111111111100000000000000001
Rotate by 18: 11111111111111000000000000000011
Rotate by 19: 11111111111110000000000000000111
Rotate by 20: 11111111111100000000000000001111
Rotate by 21: 11111111111000000000000000011111
Rotate by 22: 11111111110000000000000000111111
Rotate by 23: 11111111100000000000000001111111
Rotate by 24: 11111111000000000000000011111111
Rotate by 25: 11111110000000000000000111111111
Rotate by 26: 11111100000000000000001111111111
Rotate by 27: 11111000000000000000011111111111
Rotate by 28: 11110000000000000000111111111111
Rotate by 29: 11100000000000000001111111111111
Rotate by 30: 11000000000000000011111111111111
Rotate by 31: 10000000000000000111111111111111
Of course that causes warning, that replaces "INT_BITS_32" with "32 32UL", the compiler does not like the resulting two integers where it expects only one.