Home > Back-end >  How to define the number of bits in record bit variable?
How to define the number of bits in record bit variable?

Time:09-22

Such as IP header has four bits of data types, how to define in Delphi?

CodePudding user response:

I usually use the collection to simulate this type
 TIP_HEAD_TEST=the packed record 
In case the integer of
0: (VersionLength: the set of 0.. 7);
1: (VerLen: Byte);
end;

Var
IPHEAD: TIP_HEAD_TEST;
The begin
IPHEAD. VerLen:=$4.//set the IPV4, at the same time, the length of the qing dynasty 0
IPHEAD. VerLen:=$4 or (nLen SHL 4);//set length and IPV4, at the same time can also be SHL 3, here there seems to be a variable bit
IPHEAD. VersionLength:=IPHEAD. VersionLength + [2];//only the bit position 1, 2 is set IPV4, other unchanged
.
  • Related