Thread: How to access a Particular bit of an Memory address ????

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72

    How to access a Particular bit of an Memory address ????

    I just want to get access to a Particular Bit of a memory address...
    Remember I know the other way that is of accessing the data.. then Calculating its Binary....
    I just want to know.... How can I get access to the desired bit of any memory address directly...
    Suppose there is no = 4.
    In m/m it will store as 0000 0100 (assuming 8-bit)
    how can access its 3rd bit directly if I know its address...???
    There is a Real magic in enthusiasm, It spells the difference between mediocrity and accomplishments.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
    int TestBit(int *ptr, int bit)
      { int x = 1 << bit;
         return *ptr & x; }
    
    int main (void)
      { int test = 2022
        
         if (TestBit(test,3)
            printf("Its a 1");
         else 
           printf("its a 0");
    
         return 0; }

  3. #3
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72
    Quote Originally Posted by CommonTater View Post
    Code:
    int TestBit(int *ptr, int bit)
      { int x = 1 << bit;
         return *ptr & x; }
    
    int main (void)
      { int test = 2022
        
         if (TestBit(test,3)
            printf("Its a 1");
         else 
           printf("its a 0");
    
         return 0; }
    Thanks Man... Im also Thinking in the same way but you made it so Easily... Thanks a Lot..
    There is a Real magic in enthusiasm, It spells the difference between mediocrity and accomplishments.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-27-2011, 06:11 PM
  2. Access contents of pre-specified memory address
    By pole1080 in forum C Programming
    Replies: 5
    Last Post: 06-08-2010, 03:29 PM
  3. a library or API providing direct access to a running PE address space
    By renzokuken01 in forum Windows Programming
    Replies: 9
    Last Post: 05-24-2009, 01:40 PM
  4. Replies: 10
    Last Post: 09-04-2008, 01:27 PM
  5. Finding memory address using memory pattern
    By MindWorX in forum C++ Programming
    Replies: 1
    Last Post: 05-25-2008, 07:20 AM