[Qt-interest] Question about bitfields
Alex Strickland
sscc at mweb.co.za
Fri Jul 16 15:17:31 CEST 2010
Dan White wrote:
> Are there any Qt classes that deal with bitfields ? Or do I have to do it in
plain old vanilla C ?
If QFlags is not what you are looking for then perhaps vanilla C++:
vector< unsigned char > bitfield;
was the best I could come up with. Boost has better alternatives, as does the
new C++ standard library but I couldn't use them.
If the above will serve then this will be useful:
#ifndef BitOpsH
#define BitOpsH
#define ClearBit( buf, i ) ( ( buf )[ ( i ) / 8 ] &= ~ ( 1 << ( i ) % 8 ) )
#define SetBit( buf, i ) ( ( buf )[ ( i ) / 8 ] |= 1 << ( i ) % 8 )
#define GetBit( buf, i ) ( ( buf )[ ( i ) / 8 ] >> ( i ) % 8 & 1 )
#endif
Regards
Alex
More information about the Qt-interest-old
mailing list