|
-
Mar 21st, 2002, 01:28 PM
#1
Thread Starter
Hyperactive Member
bit wise operator
i dont understand what that line does..i know what the & does, but i dont understand why there is the 0x00FF
PHP Code:
localaddress->h_addr_list[0][3] & 0x00FF
coul anybody explain to me? thanks in advance
Amon Ra
The Power of Learning.
-
Mar 21st, 2002, 03:55 PM
#2
& 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.
-
Mar 21st, 2002, 04:09 PM
#3
Thread Starter
Hyperactive Member
so lets say that the array element == -3..
then when i do the & 0xFF, what does it become?
Amon Ra
The Power of Learning.
-
Mar 21st, 2002, 04:11 PM
#4
Fanatic Member
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
-
Mar 21st, 2002, 04:13 PM
#5
Fanatic Member
Code:
-3: 1111 1111 1111 1100
mask: 0000 0000 1111 1111 &
result: 0000 0000 1111 1100
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|