All submissions

Rotate Left in an 8-bit Register

Code

#include <stdio.h>
#include <stdint.h>

uint8_t rotate_left(uint8_t reg, uint8_t n) {
    return ((reg << n)|(reg>>(8-n))) &0xFF;
    // Your code here
}

int main() {
    uint8_t reg, n;
    scanf("%hhu %hhu", &reg, &n);
    printf("%u", rotate_left(reg, n));
    return 0;
}

Solving Approach

rotate the no.of bist given to the left and also rotate the register to right to (8-n) values and perform the addition.. and as C expands so do the OR operation with 0xFF.. this will give the circular rotation!

 

 

Loading...

Input

176 1

Expected Output

97