Logical &

Guys!
Can anybody explain to me the following?

(n&1) - What does it perform?

Sincerely, Hiken.
The logical AND is: &&
The bitwise AND is: &

We use & when we are performing bitwise operations. I do this when manually packing network packets.

Let's say I have a 16 bit word:
short MyShort = 0x69;

In binary this looks like 0000 0000 0110 1001.

Now lets say that I only want to keep the first 4 bits of that number: I would do this:
Output = MyShort & 0xf;
Which does this:
0000 0000 0110 1001 (MyShort)
0000 0000 0000 1111 & (0xf mask)
0000 0000 0000 1001 (output)


So I can easily mask the bits that I want to keep.
Last edited on
Topic archived. No new replies allowed.