I'm reading some MPEG Transport Stream protocol over UDP and it has some funky bitfields in it (length 13 for example). I'm using the "struct" library to do the broad unpacking, but is there a simple way to say "Grab the next 13 bits" rather than have to hand-tweak the bit manipulation? I'd like something like the way C does bit fields (...
I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?
...
Does is make sense to qualify bit fields as signed / unsigned?
...
So, bitfields. Specifically, large bitfields. I understand how to manipulate individual values in a bitfield, but how would I go about doing this on a large set, such as say:
uint[] bitfield = new uint[4] { 0x0080000, 0x00FA3020, 0x00C8000, 0x0FF00D0 };
The specific problem I'm having is doing left and right shifts that carry through ...
I would like to declare a record in Delphi that contains the same layout as it has in C.
For those interested : This record is part of a union in the Windows OS's LDT_ENTRY record. (I need to use this record in Delphi because I'm working on an Xbox emulator in Delphi - see project Dxbx on sourceforge).
Anyway, the record in question is...
I've just done a test with bitfields, and the results are surprising me.
class test1 {
public:
bool test_a:1;
bool test_b:1;
bool test_c:1;
bool test_d:1;
bool test_e:1;
bool test_f:1;
bool test_g:1;
bool test_h:1;
};
class test2 {
public:
int test_a:1;
int test_b:1;
int test_c:1;
int te...
I want to convert strings to bit-fields.Also,convert them to binary and then use.
Need help with this..help me ..
...
I have a set of options, some orthogonal (can be combined in any combination), some exclusive (only one from the set is allowed), and need to pick a set of enum values so that they can be combined with bit-wise or and extracted with bit-wise and. I would prefer that or-ing invalid combination would be detectable.
Are there any tools for...
Im trying to write a small class to better understand bit flags in c++. But something isnt working out. It prints the wrong values. Where is the problem? Have I misunderstood how to add flags? Or check if the bit field has them?
Heres the code:
#include <iostream>
enum flag
{
A = 1, B = 2, C = 4
};
class Holder
{
public:
Hold...
I have four flags
Current = 0x1
Past = 0x2
Future = 0x4
All = 0x7
Say I receive the two flags Past and Future (setFlags(PAST | FUTURE)). How can I tell if Past is in it? Likewise how can I tell that Current is not in it? That way I don't have to test for every possible combination.
...
Hello all,
I am using bitfields to get easy access on a float library I am trying to make for a microcontroller with no FPU.
The problem is that I can't seem to make it work with bitfields. Take a look:
typedef struct
{
union{
unsigned long mantissa: 23;
unsigned long exponent: 8;
unsigned long sign: 1;
float all;
...
In C++, I have a class which contains an anonymous bitfield struct. I want to initialize it to zero without having to manually write out all fields.
I can imagine putting the initialization in three places:
Create a constructor in the bitfield
Zero out in the initializer list of the constructor for the containing class
Zero out in th...
I am curious to know why bit fields with same data type takes less size than with mixed
data types.
struct xyz
{
int x : 1;
int y : 1;
int z : 1;
};
struct abc
{
char x : 1;
int y : 1;
bool z : 1;
};
sizeof(xyz) = 4
sizeof(abc) = 12.
I am using VS 2005, 64bit x86 machine.
A bit machine/compiler level answe...
I've seen this pattern used a lot in C & C++.
unsigned int flags = -1; // all bits are true
Is this a good portable way to accomplish this? Or is using 0xffffffff or ~0 better?
...
I'm having a very big struct in an existing program. This struct includes a great number of bitfields.
I wish to save a part of it (say, 10 fields out of 150).
An example code I would use to save the subclass is:
typedef struct {int a;int b;char c} bigstruct;
typedef struct {int a;char c;} smallstruct;
void substruct(smallstruct *s,bi...
I have a large number of instances of a C structure like this:
struct mystruct
{
/* ... */
unsigned flag: 1;
/* ... */
};
flag is initially 0 but must be 1 on exit from a certain function.
The simplest implementation is:
void set_flag(struct mystruct *sp)
{
sp->flag = 1U;
}
But what is the likely effect on perfor...
I have some struct containig a bitfield, which may vary in size. Example:
struct BitfieldSmallBase {
uint8_t a:2;
uint8_t b:3;
....
}
struct BitfieldLargeBase {
uint8_t a:4;
uint8_t b:5;
....
}
and a union to access all bits at once:
template<typename T>
union Bitfield
{
T bits;
uint8_t all; // <-...
Is there a portable way in C to find out the mask for a bit field at compile time?
Ideally, I'd like to be able to atomically clear a field like this:
struct Reference {
unsigned age : 3;
unsigned marked : 1;
unsigned references : 4;
};
struct Reference myRef;
__sync_and_and_fetch(&myRef, age, ~AGE_MASK);
Otherwise I hav...
I would like to define a large bitfield for the purpose of quickly monitoring the status a very large structure of elements. Here is what I have so far:
#define TOTAL_ELEMENTS 1021
typedef struct UINT1024_tag
{
UINT8 byte[128];
} UINT1024;
typedef struct flags_tag
{
UINT1024:TOTAL_ELEMENTS;
} flags_t;
When I try compiling this...
more of original content deleted to make question easier to reference:
So I have a House class that has a method House.buy(Person p), causing the person to buy the house. I want to know if its possible for the Person to buy the House, so I also have a method House.tryBuy(Player p) that returns if the Person can buy the house. I have an ...