Here is the code:
if(i&~077)
,
where i is an int value. The condition is supposed to be testing whether i is within a proper range. But how? Thank you very much!
Here is the code:
if(i&~077)
,
where i is an int value. The condition is supposed to be testing whether i is within a proper range. But how? Thank you very much!
~077 is the unary of the octal value 77;
octal 77 will correspond to the low order 6 bits being set of a word. In 32 bit hex word
0x0000003f.
the unary of this flips all the set bits to 0 and all 0 bits to 1 giving
0xffffffc0
this is then anded to mask off all the bits this corresponds to, in this case all the bits above bit 6.
so essentially, i = i &~077; will clear the low order six bits. if your value falls in this range then
i&~077 will return 0 else it will return a value above zero.
So in this case, if i < 64 then
i&~077 evaluates to 0 and any value of i >= 64 evaluates to i.
Thank you very much! That was such a help!!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.