Re: Please advise on bitfield endian swapping
Re: Please advise on bitfield endian swapping
- Subject: Re: Please advise on bitfield endian swapping
- From: Eric Albert <email@hidden>
- Date: Tue, 24 Jan 2006 12:22:43 -0800
On Jan 24, 2006, at 12:17 PM, Jeremy Sagan wrote:
I am converting a library written by a third person who is using
extensive bit fields for their data structure and I was wondering
if anyone has a generalized solution to swapping the endianness of
bit fields where a file originated on powerpc.
Things like this:
typedef struct test
{
Byte needsrepair : 1;
Byte isMute : 1;
Byte track :6;
};
I am thinking that one solution would be to have a conditional
compilation for little endian so that it first reverses the
structure so that in the above case for little endian the structure
would be:
typedef struct test
{
Byte track :6;
Byte isMute : 1;
Byte needsrepair : 1;
};
Then the endian code would still, correct me if I am wrong, have to
go through and swap the bitfields that are more than one bit. In
the above case the field 'track' would be a 6 bit value from 0-63
but the bits are still reversed.
Yep. The example in the Archived Bit Fields section of the
Guidelines for Specific Scenarios chapter of the Universal Binary
Programming Guidelines should work for you for this case.
It's a bit more complicated when you have an individual bitfield that
crosses byte boundaries. Hopefully you don't have any of those.
-Eric
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden