gnupic: Bit variables in C
Subject:
Re: Bit variables in C
From:
Scott Dattalo ####@####.####
Date:
15 Nov 2000 13:08:07 -0000
Message-Id: <Pine.LNX.4.21.0011150705130.18530-100000@tempest2.blackhat.net>
On Wed, 15 Nov 2000, Alex Holden wrote:
> One problem, how do you represent a pointer to a single bit
> variable?
That's a good question. The short answer is I don't know (at least
efficiently). At some point after the pointer has been dereferenced, the FSR
would contain the address of the bit. Bit addresses are different than byte
addresses - or I should say, they map into the byte addresses like so:
byte address = bit address >> 3
then the desired bit is one of the eight at the byte address:
specific bit = ( (*byte_address)>>(bit_address & 3) ) & 1
The shift operation can be done implicitly if the value of bit_address is known
apriori. Unfortunately, if you've got a pointer to it, then you'll have to
explicitly shift. The lower 3 bits of bit_address will be known only at run
time. I do have algorithms for taking a 3-bit number and computing (1<<n), but
it still looks heinous.
Scott