All submissions

Bit Operations using Macros

Code

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

// Define bitwise macros here
#define SetBit2     2
#define SetBit7     7
#define ClearBit3   3
#define Toggle5     5


uint8_t modify_register(uint8_t reg) {
    
    // Apply operations in order
    reg |= (1<<SetBit2);
    reg |= (1<<SetBit7);
    reg &= (~(1<<ClearBit3));
    reg ^= (1<<Toggle5);

    return reg;
}

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

Solving Approach

 

 

 

Loading...

Input

0

Expected Output

164