Consider a variable unsigned int a; in C.
unsigned int a;
Now say I want to set any i\'th bit in this variable to \'1\'.
Note that the variable has some value.
You could probably use
a |= (1 << i)
But it won't make much of a difference. Performance-wise, you shouldn't see any difference.
You might be able to try building a table where you map i to a bit mask (like 2 => 0x0010 for 0000000000100), but that's a bit unnecessary.
i
2
0x0010
0000000000100