i dont understand what that line does..i know what the & does, but i dont understand why there is the 0x00FF
coul anybody explain to me? thanks in advancePHP Code:localaddress->h_addr_list[0][3] & 0x00FF
Printable View
i dont understand what that line does..i know what the & does, but i dont understand why there is the 0x00FF
coul anybody explain to me? thanks in advancePHP Code:localaddress->h_addr_list[0][3] & 0x00FF
& tiwddles bits, && does a boolean operation.
The 0xFF thing has the last 8 bits on,
& then twiddles the last 8 bits of array element to on.
so lets say that the array element == -3..
then when i do the & 0xFF, what does it become?
The 0x00FF thing is called a mask. You can compare the working of these masks with the usage of masks in drawing programs.
The & operator doesn't turn the last 8 bits of the array element on, but retrieves for you the last 8 bits of that array element.
A quick example:
Code:arrayEl: 0010 1010 1101 0001
mask: 0000 0000 1111 1111 &
result: 0000 0000 1101 0001
The value of result is 252. The mask is 255 (0x00FF), but NEVER use this for regular calculations. Since the & operator is a bitwise operator, you can only use it to set or retrieve bits.Code:-3: 1111 1111 1111 1100
mask: 0000 0000 1111 1111 &
result: 0000 0000 1111 1100