Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
See more:
Does C# support struct bit definitions?. For example is there a way to
declare a structure like this in c#.

C#
typedef struct
{
    UINT16 SrcPort;
    UINT16 DstPort;
    UINT32 SeqNum;
    UINT32 AckNum;
    UINT16 Reserved1:4;
    UINT16 HdrLength:4;
    UINT16 Fin:1;
    UINT16 Syn:1;
    UINT16 Rst:1;
    UINT16 Psh:1;
    UINT16 Ack:1;
    UINT16 Urg:1;
    UINT16 Reserved2:2;
    UINT16 Window;
    UINT16 Checksum;
    UINT16 UrgPtr;
} DIVERT_TCPHDR


Please help me to set bit positions in c# structure. It is very urgent.
Posted
Updated 19-Sep-13 1:29am
v2

The simple answer is "no" - there is no C# equivalent of C++ bit fields.

However you might want to have a look at this: http://stackoverflow.com/questions/14464/bit-fields-in-c-sharp[^] which does provide a helper class that might assist, with a bit of work.
 
Share this answer
 
At Stack Overflow some ideas: "Bit fields in C#"[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900