Thread: Bitwise AND -> equality test

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    107

    Bitwise AND -> equality test

    I am trying to write a bitmapped memory manager just for the exercise of doing it, and I am having trouble with a little function I am trying to write. The idea of it is that it does a simple linear scan through a bitmap to try to find a consecutive run of 1s in the bitmap long enough to satisfy our demands and returns the starting position of that run. Never mind that the function does no such thing at the moment. I am just trying to get the first part right: scan until we find the first 1. But the problem is that my equality test seems not to be working. Could someone please explain why?
    Code:
    int _Find_Contiguous_Blocks(int blocks)
    {
    	unsigned long bit = 0x1;
    
    	while(bit & bitmap == 0x0UL)
    	{
    		bit = uint_64_rotate_left_1(bit); // Never seems to get executed....
    	}
    	printf("%lx\n", bit);
    
    
    	return 0;
    }
    I have arbitrarily set the first eight bits to be zero, so the initial state of the bitmap is 0xffffffffffffff00. When I run the function I expect the bit to be rotated to the left eight times and to print out 8. Instead, it prints out 1, which was the initial value.

    What am I doing wrong?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > What am I doing wrong?
    Not understanding the precedence table.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    107
    Quote Originally Posted by Salem View Post
    > What am I doing wrong?
    Not understanding the precedence table.
    Oh ........ ya, parens worked fine there. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 12:12 PM
  2. Dev-C++ -> Tools - > Editor -> Syntax
    By Yuri2 in forum C++ Programming
    Replies: 19
    Last Post: 07-03-2006, 07:48 AM
  3. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 02:06 PM
  4. electricity > AC circuits > tesla coil
    By dbaryl in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 03-14-2002, 02:16 PM