Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
- Subject: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
- From: Steve Christensen <email@hidden>
- Date: Tue, 27 Jan 2009 14:27:33 -0800
On 27 Jan 2009, at 14:23, Adam Venturella wrote:
The file I am
reading is assured to be in little-endian, and I am checking what the
host byte ordering is first. Leopard is little endian ( at least on
the intel chips, but I have read there are other macs that are
big-endian, so I am trying to catch and handle that accordingly)
Adam: Repeating a comment from an earlier reply, you should just use
the supplied functions in <Foundation/NSByteOrder.h>. They will work
correctly whether you're building for a little-endian Intel processor
or a big-endian PowerPC processor. Then you don't have to
specifically "catch and handle" anything. So for your case of little-
endian data being read from a file:
unsigned short NSSwapLittleShortToHost(unsigned short x);
unsigned int NSSwapLittleIntToHost(unsigned int x);
unsigned long NSSwapLittleLongToHost(unsigned long x);
unsigned long long NSSwapLittleLongLongToHost(unsigned long long x);
double NSSwapLittleDoubleToHost(NSSwappedDouble x);
float NSSwapLittleFloatToHost(NSSwappedFloat x);
steve
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden