Rotate Left in an 8-bit Register

Code

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

uint8_t rotate_left(uint8_t reg, int n){
    uint8_t result = (reg << n) | (reg >> (8 - n));
    return result;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

176 1

Expected Output

97