• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Please advise on bitfield endian swapping
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Please advise on bitfield endian swapping (From: Jeremy Sagan <email@hidden>)

  • Prev by Date: Please advise on bitfield endian swapping
  • Next by Date: "Clear log" button... Grrrr.....
  • Previous by thread: Please advise on bitfield endian swapping
  • Next by thread: "Clear log" button... Grrrr.....
  • Index(es):
    • Date
    • Thread