Thread: bit manipulation

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    29

    bit manipulation

    Hi folks,

    volatile unsigned *general_pointer;

    general_pointer += ((*(some_structure->some_pointer_member)>>8)&0x07F);


    I'm stuck on this part of a C code, what is actually being done here? Especially that shift by 8 and the '&0x07F' after the bracket?

    Thanks.
    Disk space: the final frontier

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    The shift and mask would take a value whose binary representation might be as follows
    Code:
    1010100110110101
    and result in what is in blue.

    [edit]The shift results in a value, continuing with the above example, such as this.
    Code:
    10101001
    The mask clears bit 7, resulting in this.
    Code:
    00101001
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    <QUOTE>
    The mask clears bit 7, resulting in this.
    Code:
    00101001
    </QUOTE>

    Don't you mean the mask clears bit 8?
    Disk space: the final frontier

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    No, I mean bit 7. (Starting from bit 0.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    Ok. Got you.
    Disk space: the final frontier

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Come to think of it, I should have said that it clears bit 7 on up. (I was thinking in 8-bit bytes.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    Ok thought so.
    Disk space: the final frontier

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 32 bit to 64 bit Ubuntu
    By Akkernight in forum Tech Board
    Replies: 15
    Last Post: 11-17-2008, 03:14 AM
  2. bit value check efficiency
    By George2 in forum C Programming
    Replies: 5
    Last Post: 11-05-2007, 07:59 AM
  3. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  4. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  5. Copy bit to bit
    By Coder2Die4 in forum C Programming
    Replies: 15
    Last Post: 06-26-2003, 09:58 AM