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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -