V
vib
Hi there,
union UC32 {
unsigned int L;
unsigned short S[2];
unsigned char C[4];
} UC32;
with the above structure, I am able to shift bits of C[0], into C[1],
and C[1] into C[2] so on and so forth till C[3] as they are "union"ed
with unsigned int L.
However, the problem comes when I need more than the primitive datatype
can handle, let's say as 10 bytes.
my attempt is:
unsigned char ar[10];
unsigned temp;
signed char i, j;
for (i = 9; i > 0; i --)
{
if ( ar[i-1] & 0x80)
{
ar = ar << 1 | 0x01;
}
else
ar = ar << 1;
}
ar[0] = ar[0] << 1;
i don't quite like this approach. All comments and suggests are
welcome.
Thanks
vib
union UC32 {
unsigned int L;
unsigned short S[2];
unsigned char C[4];
} UC32;
with the above structure, I am able to shift bits of C[0], into C[1],
and C[1] into C[2] so on and so forth till C[3] as they are "union"ed
with unsigned int L.
However, the problem comes when I need more than the primitive datatype
can handle, let's say as 10 bytes.
my attempt is:
unsigned char ar[10];
unsigned temp;
signed char i, j;
for (i = 9; i > 0; i --)
{
if ( ar[i-1] & 0x80)
{
ar = ar << 1 | 0x01;
}
else
ar = ar << 1;
}
ar[0] = ar[0] << 1;
i don't quite like this approach. All comments and suggests are
welcome.
Thanks
vib