LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C code if (get_le_long(buf + 96) & 0x0008) ??? (https://www.linuxquestions.org/questions/programming-9/c-code-if-get_le_long-buf-96-and-0x0008-391759/)

Bluesuperman 12-11-2005 10:36 PM

C code if (get_le_long(buf + 96) & 0x0008) ???
 
Hello,

I do not understand the following piece of code:

if (get_le_long(buf + 96) & 0x0008)

What does the "&" do ? I believe get_le_long retrieves 96 bytes from buf ? But is the "&" active like a place holder ?

Thanks

Michael

paulsm4 12-11-2005 11:36 PM

"get_le_long()" returns the little-endian 32-bit integer long that it finds at network buffer position "buf+96".

The "&" is the C bitwise "and" operator.

Let's say the value at buf+96 is "6". The value will be:

0x0000 0006
& 0x0000 0008
-----------
0000 0000

Why?
decimal(6) = binary(0110)
decimal(8) = binary(1000)

Left-to-right:
0 AND 1 = 0
1 AND 0 = 0
1 AND 0 = 0
0 AND 0 = 0


All times are GMT -5. The time now is 08:37 AM.