Board index » delphi » Variable size variables

Variable size variables

 I hope someone can answer this puzzler for me...

  I have a project that uses data packed into a bit stream. Inside the
stream are a number of fields, each a certain number of bits wide.
This number can vary from 1 to 24 bits, depending on the field. In
C++, I could declare a structure like this

 Typedef struct {

int field1  :2;   // variable 1 is 2 bits wide
int field2  :5;  //      "        2 " 5  "      "
int field3  :7;  //      "        3 " 7  "      "

Quote
}

Is there any way to do the same thing in Delphi?
 

Re:Variable size variables


Quote
Joe Andrews wrote:

>  I hope someone can answer this puzzler for me...

>   I have a project that uses data packed into a bit stream. Inside the
> stream are a number of fields, each a certain number of bits wide.
> This number can vary from 1 to 24 bits, depending on the field. In
> C++, I could declare a structure like this

>  Typedef struct {

> int field1  :2;   // variable 1 is 2 bits wide
> int field2  :5;  //      "        2 " 5  "      "
> int field3  :7;  //      "        3 " 7  "      "
> }

> Is there any way to do the same thing in Delphi?

        Pretty sure you can't handle bit-size field quite this
way in Delphi (I'd love to have someone explain how wrong I am
on this one!) Seems like the smallest thing you can access is a
byte - then you can test bits in your byte. Or you can sometimes
use a set for bitfields...

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Other Threads