Results 1 to 5 of 5

Thread: bit wise operator

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    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.

  2. #2
    jim mcnamara
    Guest
    & 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.

  3. #3

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    so lets say that the array element == -3..
    then when i do the & 0xFF, what does it become?
    Amon Ra
    The Power of Learning.

  4. #4
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    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

  5. #5
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    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
  •  



Click Here to Expand Forum to Full Width