R
Ramesh
Hi
I have a structure as below on big endian based system
typedef struct
{
unsigned long LedA:5;
unsigned long LedB:4;
unsigned long LedC:8;
unsigned long LedD:4;
unsigned long LedE:5;
unsigned long LedF:6;
}regs_t;
#define get_LedStatus(x) ((regs_t *)(&x))->LedA
main() {
unsigned long LedReg = 0x80000000;
printf("%X", get_LedStatus(LedReg))
}
On a big endian based system - I get a value of 0x1 as output.
For the little endian based system, I define the structure as below:
typedef struct
{
unsigned long LedF:6;
unsigned long LedE:5;
unsigned long LedD:4;
unsigned long LedC:8;
unsigned long LedB:4;
unsigned long LedA:5;
}regs_t;
I get a value as 0x10, so instead of getting a bit pattern like 0
0001
what I get is 1 0000
While reversing the bits solves the problem - Any insights as to what
could be the best solution if I have several such structures to be
ported from big endian to little endian system?
BTW the target is Linux 2.6 on x86 & gcc 4.12.2xxxx
Thanks
/R
I have a structure as below on big endian based system
typedef struct
{
unsigned long LedA:5;
unsigned long LedB:4;
unsigned long LedC:8;
unsigned long LedD:4;
unsigned long LedE:5;
unsigned long LedF:6;
}regs_t;
#define get_LedStatus(x) ((regs_t *)(&x))->LedA
main() {
unsigned long LedReg = 0x80000000;
printf("%X", get_LedStatus(LedReg))
}
On a big endian based system - I get a value of 0x1 as output.
For the little endian based system, I define the structure as below:
typedef struct
{
unsigned long LedF:6;
unsigned long LedE:5;
unsigned long LedD:4;
unsigned long LedC:8;
unsigned long LedB:4;
unsigned long LedA:5;
}regs_t;
I get a value as 0x10, so instead of getting a bit pattern like 0
0001
what I get is 1 0000
While reversing the bits solves the problem - Any insights as to what
could be the best solution if I have several such structures to be
ported from big endian to little endian system?
BTW the target is Linux 2.6 on x86 & gcc 4.12.2xxxx
Thanks
/R