Afficher un message
Vieux 18/10/2007, 14h55   #3
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding number of bits of integer

Richard Heathfield <rjh@see.sig.invalid> writes:

> Daniel Kraft said:
>
>> I do need to implement something similar to C++'s std::bitset in C;

<snip>
> The usual way to implement a "bit array", though, is as follows:

<snip>
> 2) allocate (B + CHAR_BIT - 1) / CHAR_BIT bytes (unsigned char
> foo[N] = {0}

<snip>

It is probably worth adding the reason one uses an unsigned integer
type is that shift operations are well-defined on these, and the
reason one uses unsigned char in particular is that it is guaranteed
not to have any padding bits.

--
Ben.
  Réponse avec citation
 
Page generated in 0,04117 seconds with 9 queries