c++ - How to get all ones or all zeros from boolean result? -
i (stupidly) thought if took boolean result of true, cast int , left-shifted end lsb repeated @ every bit, not!
if had boolean result , wanted convert ones true , zeros false, cheapest way (computationally) this?
bool result = x == y; unsigned int x = 0; //x becomes ones when result true //x becomes zeros when result false
like this, perhaps:
bool result = x == y; unsigned int z = -result;
Comments
Post a Comment