A good source for such problems is
Bit Twiddling Hacks[
^]. See '
Conditionally set or clear bits without branching' for your task. Adding an instruction to generate the mask, this can be used:
unsigned m = 1U << i;
B ^= (-b ^ B) & m;
B = (B & ~m) | (-b & m);