Top "Bit-fields" questions

A bit field is used to compactly store multiple logical values as a short series of bits where each of the single bits can be addressed separately.

Does Python have a bitfield type?

I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I …

python bit-fields bitarray
Is it safe to use -1 to set all bits to true?

I've seen this pattern used a lot in C & C++. unsigned int flags = -1; // all bits are true Is …

c++ c binary bit-fields
Why bit endianness is an issue in bitfields?

Any portable code that uses bitfields seems to distinguish between little- and big-endian platforms. See the declaration of struct iphdr …

c cross-platform portability low-level bit-fields
When is it worthwhile to use bit fields?

Is it worthwhile using C's bit-field implementation? If so, when is it ever used? I was looking through some emulator …

c++ c bit-fields
Is it valid to use bit fields with union?

I have used bit field with a structure like this, struct { unsigned int is_static: 1; unsigned int is_extern: 1; unsigned …

c structure bit-fields unions
Declaring and using a bit field enum in Swift

How should bit fields be declared and used in Swift? Declaring an enum like this does work, but trying to …

enums swift bit-fields
How is the size of a struct with Bit Fields determined/measured?

#include <stdio.h> typedef struct size { unsigned int a:1; unsigned int b:31; unsigned int c:1; } mystruct; int main() { …

c bit-fields
Using Bitwise operators on flags

I have four flags Current = 0x1 Past = 0x2 Future = 0x4 All = 0x7 Say I receive the two flags Past and …

c# .net bit-manipulation bit-fields
C++11 standard conformant bitmasks using enum class

Can you implement standard conformant (as described in 17.5.2.1.3 of the n3242 draft) type safe bitmasks using enum class? The way …

c++ c++11 bit-fields bitmask enum-class
Packed bit fields in c structures - GCC

I am working with structs in c on linux. I started using bit fields and the "packed" attribute and I …

c gcc struct bit-fields packed