bitwise AND'ing with octal 0100 ought to do the job as in
Code:i = (var1 & 0100) ? 128 : 0;
bitwise AND'ing with octal 0100 ought to do the job as in
Code:i = (var1 & 0100) ? 128 : 0;
Ehm, yes, if bit 7 is the bit worth 64, then I would agree that this would achieve the desired effect - but the terniary operator is often implmented as a if-statement, so may lead to a branch, so if this is REALLY what you want to do, then:
will achieve the same thing, guaranteed to be without a branch.Code:i = (var1 & 64) << 1;
Using octal will achieve nothing special here.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Yes the ternary operator is a contraction of the if-else; the octal's only for the effect; and i = (var1 & 64) << 1; is a clever one