You are using a version without Ads of this website. Please, consider donating:

### what does the following line means

Hi guys.

In this faq:
http://www.parashift.com/c++-faq-lite

& is used many times in a line of the following type:

`if (n < 256U) or if ((n & 255u) < 32u)`

What does it mean? I can't really understand the logic of this use. Just to make it clear, n is of int type.

Thanks.
Bit-wise AND.

thanks.

I read about this. I'm not sure I can understand the logic of the test but this has nothing to do with my question.
I tire of rudeness.

 What does it [the '&' sign] mean?
Our friendly jsmith answered your question directly and exactly -- it has everything to do with your question, as it is the only available correct answer.

As you are still confused, I think you need more reading.
http://en.wikipedia.org/wiki/Bitwise_operation#AND

Why exactly you would find a line of code like you listed depends entirely upon the range of values that `n` may take. (It also presumes a valid line of code.)
To be honest, I don't think he was rude. When he said this has nothing to do with my quesiton, I think he referred back to when he said I'm not sure I can understand the logic of the test.

 I'm not sure I can understand the logic of the test but this has nothing to do with my question.

(He can't understand the logic but he's saying that that has nothing to do with his 'question' being What does it[the '&' sign] mean?)
Duoas.

please read my replay again. I meant exactly the opposite of what you think.

What I meant is that the logic of the test has nothing to do with my question. Off course that the answer of jsmith was relevant to my question as this is the test that is being done.

Sorry if I have offended you or jsmith in ANY way.

Yotam
n & 255u

255 in binary is 11111111 (eight 1s)

u means to treat the value as unsigned (int). On a 32-bit platform, this results in the binary value:

00000000 00000000 00000000 11111111

From boolean math, we know that x & 0 == 0, and x & 1 == x.

Therefore the result of the operation ( n & 255u ) is just the lower 8 bits of n.

So if( ( n & 255u ) < 32u )

says essentially to compare the lower 8-bits of n to 32.
jsmith.

Thanks.

What I still don't understand is why the two tests are equivalent?

There is a good chance that the two are not and they are simply brought as an example.
 What I still don't understand is why the two tests are equivalent?

If you mean `if(n < 256U)` and `if((n & 255u) < 32u)`, then they're not equivalent at all.
Great so all I got to do is read this paragraph again.

Thanks guys.

Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: