You can make use of the power of union for this
union value
{
uint32 number;
struct bytes
{
uint8 bytevalue[4];
};
};
Question
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];
};
};
OTHER TIPS
UINT32 value;
UINT8 byteval[4];
for(int i = 0 < 4; i++)
byteval[i] = value >> (i*8);
Use Structure & Union in combination.
typedef struct
{
uint32 ArrayOf32Bit[8];
}Arrayof32bitVar_t;
typedef union
{
Arrayof32bitVar_t Var8int32;
uint8 Array8char[8*4]; // instead use macro
}tydefUnion_t;
func_add
{
int i
tydefUnion_t a; //
/*Here update variable a.Var8int32.ArrayOf32Bit*/
int addResult = 0;
for(i;i<(8*4);i++)
{
addResult += a.Array8char[i];
}
}