Bitwise AND -> equality test

This is a discussion on Bitwise AND -> equality test within the C Programming forums, part of the General Programming Boards category; I am trying to write a bitmapped memory manager just for the exercise of doing it, and I am having ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 01: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, 01:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21