I'm a bit rusty on bitwise operators, and I don't know what data types "u8" and "u16" are, but the general function would be something like this:
"val" is a value passed to the function.
In the "for()" loop, "val" is shifted over by 'c' bits and logic-ANDed with BIT15.
If we assume "val" = 0x0800, then you can follow it like this:
Code:
(val << c) & BIT15
// c == 0
// shift val left 0 bit(s)
// val = 0x0800 = 0000 1000 0000 0000
// & BIT15: 1000 0000 0000 0000
// -------------------
// 0000 0000 0000 0000
// "if()" is false, so output is PC7_LOW
(val << c) & BIT15
// c == 1
// shift val left 1 bit(s)
// val = 0x1000 = 0001 0000 0000 0000
// & BIT15: 1000 0000 0000 0000
// -------------------
// 0000 0000 0000 0000
// "if()" is false, so output is PC7_LOW
(val << c) & BIT15
// c == 2
// shift val left 2 bit(s)
// val = 0x2000 = 0010 0000 0000 0000
// & BIT15: 1000 0000 0000 0000
// -------------------
// 0000 0000 0000 0000
// "if()" is false, so output is PC7_LOW
(val << c) & BIT15
// c == 3
// shift val left 3 bit(s)
// val = 0x4000 = 0100 0000 0000 0000
// & BIT15: 1000 0000 0000 0000
// -------------------
// 0000 0000 0000 0000
// "if()" is false, so output is PC7_LOW
(val << c) & BIT15
// c == 4
// shift val left 4 bit(s)
// val = 0x8000 = 1000 0000 0000 0000
// & BIT15: 1000 0000 0000 0000
// -------------------
// 1000 0000 0000 0000
// "if()" is true, so output is PC7_HIGH