Bit Operations using Macros

Code

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

// Define bitwise macros here

uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    uint8_t set_mask = 0b10000100;
    uint8_t clear_mask = 0b1000;
    uint8_t toggle_mask = 0b100000;
    reg = reg|set_mask;
    reg = reg & (~clear_mask);
    reg = reg ^ toggle_mask;
    return reg;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

0

Expected Output

164