Re: Bit twiddling



Paul Mesken <usurper@xxxxxxxxxx> writes:
[...]
> No, because you cannot have an array of bitfields (something like
> "signed int Bit[8]:1;").
>
> Just *don't* use bitfields in this case. You cannot know in which
> order they are represented (left to right or right to left).

Right.

[...]

> Still, you cannot be sure whether Bit1 is bit 0 of that integer or bit
> 31 (if int is 32 bits).
>
> By the way : the least significant bit of some value is, typically,
> not called "bit 1" but "bit 0".

Whether bit 0 is the least or most significant bit is probably
system-specific; the bits in a 32-bit word might be numbered 0..31 or
31..0. Which way they're numbered is probably more a matter of
terminology than actual semantics, unless the CPU provides
instructions that take bit numbers as arguments.

Since C doesn't define any kind of numering for bits, the question
isn't relevant for portable code.

When you declare a bit field, you're asking the compiler to allocate a
bit in a structure. You're not telling it which one.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.