Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- void printBin(uint8_t x) {
- for (int i = sizeof(x) * 8 - 1; i >= 0; i--) {
- printf("%d", 1 & (x >> i));
- if (i % 4 == 0) {
- putchar(' ');
- }
- }
- puts("");
- }
- int leftRot(uint8_t v, int n) {
- return (v << n) | (v >> (sizeof(v) * 8 - n));
- }
- int main(void) {
- uint8_t v;
- int n;
- printf("v="); scanf("%hhu", &v);
- printf("n="); scanf("%d", &n);
- printBin(v);
- printBin(leftRot(v, n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement