[riot-notifications] [RIOT-OS/RIOT] core/bitarithm: introduce bitarithm_get/set_masked(), convert pca9685 (#12238)

benpicco notifications at github.com
Mon Sep 16 22:14:06 CEST 2019


> An example would be nice. I don't quite get it. Like, byte=0b0110, mask=0b0011, bit=0b1001 => result = 0b0001"?

Often times you have multiple variables in one register, e.g. bits 0-3 are `foo` and bits 4-7 are `bar`.

```C
union {
    uint8_t foo:4;
    uint8_t bar:4;
} byte
```

Now to set `bar` in `byte` you would do `mask=0b11110000`, the if `byte=0b00000110` and `bit=0b1001` => `result = 0b10010110`.

In your example `result` would be `0b0101`.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/12238#issuecomment-531939298
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190916/d6a183bb/attachment.htm>


More information about the notifications mailing list