All submissions

Bit Operations using Macros

Code

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


// Define bitwise macros here
#define set1 2
#define set2 7
#define clear 3
#define tog 5
uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    reg |= (1<<set1);
    reg |= (1<<set2);
    reg &= ~(1<< clear);
    reg ^= (1<< tog);
    return reg;
}

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

Solving Approach

Defining all the macros.

Applying all the operations in order in the function.

 

 

 

Loading...

Input

0

Expected Output

164