10. Bit Operations using Macros

Discussions2
Log in to post comments and replies.
You
Loading editor...
TechnicalAB
TechnicalAB
Feb 12 2026

yo can anyone help me im learning embedded c and have no idea or sources where to study from is this website good enough?

 

0
lokeshloki6870
lokeshloki6870
Jun 14 2026
#include <stdio.h>
#include <stdint.h>

// Define bitwise macros here

uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    /*reg = reg | (1<<2);
    reg = reg |(1<<7);
    reg = reg & ~(1<<3);
    reg = reg ^(1<<5);
    return reg;*/
    return (((reg | (1<<2) | (1<<7)) &~(1<<3)) ^(1<<5));
}

int main() {
    uint8_t reg;
    scanf("%hhu", &reg);
    printf("%u", modify_register(reg));
    return 0;
} 
 We can also do like this 
-2