Questions tagged [bit-fields]

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.

A bit field is used to represent and store a set of known width and logically grouped set of values. These fields can then be addressed individually in the code. A common use of such a construct is flags.

In language such as C and C++, bit fields can also be used to abstract and interop with specific hardware.

857 questions
0
votes
2 answers

Packed Bit Fields in Python

I want to pack a 10-bit integer and a 54-bit integer into a 64-bit structure. But this code ends up using 128 bits. from ctypes import * class ABC(Structure): _fields_ = [("a", c_int, 10), ("b", c_uint64, 54)] print(sizeof(ABC) * 8) # 128
mcu
  • 3,302
  • 8
  • 38
  • 64
0
votes
1 answer

Webpage - Adding data to SQL table - Yes, no, or null

Redesign of webpage problem - I have a field in my SQL database called Approved. This field was either true for approved, or false for not approved. Now, the user would like to track denied. So, it's approved - true, not approved - false, or not…
user3033348
  • 145
  • 13
0
votes
1 answer

C++ Variable Width Bit Field

I'm writing a program that is supposed to manipulate very long strings of boolean values. I was originally storing them as a dynamic array of unsigned long long int variables and running C-style bitwise operations on them. However, I don't want the…
Woody1193
  • 7,252
  • 5
  • 40
  • 90
0
votes
3 answers

Setting a bit field in C

I'm trying to write a function that will set a field of bits to a certain value. The function is int setField(int old, int hi, int lo, int new). I need it to take the range of bits (lo to hi) from the old value and replace them with the new value.…
Kareem Youssef
  • 37
  • 1
  • 3
  • 11
0
votes
2 answers

Type casting struct to integer and vice versa in C++

So, I've seen this thread Type casting struct to integer c++ about how to cast between integers and structs (bitfields) and undoubtly, writing a proper conversion function or overloading the relevant casting operators is the way to go for any cases…
mox
  • 141
  • 2
  • 8
0
votes
1 answer

XML to Python Class to C Struct

I need some advice. Two questions, does something already exist for this, what modules should I use to develop this. I have some structures that come from an XML file. I want to represent them in Python Classes (maybe using a factory to create a…
ChipJust
  • 1,376
  • 12
  • 20
0
votes
2 answers

16bit bitfield leads to *read from uninitialised memory* warning

I have this typedef: typedef union { unsigned Value; unsigned Timestamp:16; } BITFIELD; and get this compiler warning: BITFIELD bitfield; // read from uninitialised memory - may result in unexpected behaviour bitfield.Timestamp = 12; Now,…
tanascius
  • 53,078
  • 22
  • 114
  • 136
0
votes
1 answer

Bit-fields at two separate locations in a Structure in C

In a structure we normally have contiguous bit-fields; that is, one after the other and adjacent to each other — for example: struct demo { char a; char b:1; char c:2; char d:2; int e; } demo1; The size of demo1 will be 8 bytes: size…
Paul Sen
  • 526
  • 1
  • 4
  • 20
0
votes
2 answers

How are single-bit (boolean) members in bit fields handled?

When I request or set a single-bit member of a bit-wise struct/class, does the compiler do a bit shift? For example, given this struct: struct { unsigned char thing : 4; unsigned char flag1 : 1; unsigned char flag2 : 1; unsigned char…
Phlucious
  • 3,704
  • 28
  • 61
0
votes
3 answers

Bit field memory

If i declare something like this struct S{ unsigned int bit:4; } How is it working? I allocate 2 bytes in memory(size of structure(got this size from here http://en.cppreference.com/w/cpp/language/bit_field) but use only 4 bits of it, and other…
bingo157
  • 113
  • 1
  • 2
  • 12
0
votes
1 answer

Unions and bit fields — how do they work?

I have some problems when trying to understand this code: #include typedef union { int entero; struct { unsigned short : 7; unsigned short valor: 1; } bin; } conversor; int main(void) { int numero = 8,…
Kevin
  • 1,151
  • 1
  • 10
  • 18
0
votes
1 answer

vBulletin 4 Fetch thread permissions by external php-application

I am writing an addon to display the latest threads/posts of an vBulletin 4 forum in an extern application. Both systems are running on the same domain so that I'm able to get the vB session of the user in the external application. Because the vB…
Lion
  • 16,606
  • 23
  • 86
  • 148
0
votes
1 answer

Represent the colour of a bit field

Can anyone show me a (language agnostic) way to assign a colour value to a bit field so that comparatively similar bit fields have a similar colour to each other. So for example 01100111 And 01110111 Are close in colour relatively.…
HedgepigMatt
  • 190
  • 3
  • 16
0
votes
1 answer

Address bits within uint8_t as members of struct

I am currently writing code for a PIC micro-controller and I would like to structure some of my code using a uint8_t as a "state counter" for a part of my code. This involves a lot of bitwise operations. What I'd like to do is create a struct for…
RobbG
  • 371
  • 5
  • 14
0
votes
1 answer

bit fields variable naming convention and invalid type error gcc 4.2.1 freebsd 7

I am migrating php from 5.3 to 5.5. I am doing cross compilation in freebsd 7 - gcc 4.2.1 Compiling for arm, i386 and powerpc. a source file is not compiling. Following is the code similar the real one. typedef struct _abc { char *d; …
Jayapal Chandran
  • 10,600
  • 14
  • 66
  • 91