Hi!
I am looking for a good way of assigning a specific bit in a variable the value of a specific bit in another variable.
For example bit 2 in variable a = bit 5 in variable b.
Any suggestions?
//John
Hi!
I am looking for a good way of assigning a specific bit in a variable the value of a specific bit in another variable.
For example bit 2 in variable a = bit 5 in variable b.
Any suggestions?
//John
Maybe not the best way, but:
Code:unsigned a = 0x00, b = 0xff; int abit = 2, bbit = 5; if (b & (1 << bbit)) a |= (1 << abit); else a &= -1 ^ (1 << abit);
-1 ^ is a curious way of saying ~
Thanks for helping!