Search code examples
carrayscharunsigneduint32

How to uint32 to unsigned char array


I have 8 uint32 elements and i want to break each uint32 into 4 uint8 then add all uint8 beside each others as unsigned chars in the array , how can i do that ?


Solution

  • You can make use of the power of union for this

    union value
    {
       uint32 number;
    
       struct bytes
       {
           uint8 bytevalue[4];
       };
    };