0
typedef union
{
    volatile struct
    {                                      //Init 
        UINT64      ARG1                : 1; //800H
        UINT64      ARG2                : 1; //800H
        UINT64      ARG3                : 1; //00H
        UINT64      ARG4                : 1; //00H      
        UINT64      ARG5                : 2; //00H  
        UINT64      ARG6                : 1; //00H  
        UINT64      ARG7                : 1; //00H  
        UINT64      ARG8                : 8; //00H  
        UINT64      ARG9                : 16;//00H  
        UINT64      ARG10               : 8; //00H  
        UINT64      ARG11               : 8; //00H  
        UINT64      ARG12               : 8; //00H  
        UINT64      ARG13               : 8; //00H          
    }Signal;
    UINT8               Data[8];    
}Pack;

I want to know how to implement data in c#. I know I could use StructureLayout, but the declared memory size is different from c. I want the output to be 00-00-80-00-00-00-00-00-00.

timrau
  • 22,578
  • 4
  • 51
  • 64
  • 1
    Use an array of bytes and explicit bit-handling when needed? – Some programmer dude Dec 16 '21 at 09:59
  • @Someprogrammerdude I don't even know how to do it. I have little knowledge about the structure of c.I'm working on an example datasheet on the Internet for 'can protocol'. –  REPEATSIT Dec 16 '21 at 10:16
  • Please note that this code alone is not enough to tell us which order the fields are. C standard says that **C compiler can put bit-fields in any order they wish.** So you need probably will need to read that information from manual of the compiler that this code was written for. – user694733 Sep 05 '22 at 09:50
  • Also, comments do not make any sense: `ARG1` is supposed to be single bit field. It cannot fit hexadecimal value `0x800` into it. – user694733 Sep 05 '22 at 09:51

0 Answers0