• 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: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare (From: William Jon Shipley <email@hidden>)
 >Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare (From: Adam Venturella <email@hidden>)
 >Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare (From: Jeremy Pereira <email@hidden>)

  • Prev by Date: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
  • Next by Date: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
  • Previous by thread: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
  • Next by thread: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
  • Index(es):
    • Date
    • Thread