Re: Tiger Decoding problem
Re: Tiger Decoding problem
- Subject: Re: Tiger Decoding problem
- From: Nicholas Crosbie <email@hidden>
- Date: Tue, 31 May 2005 11:54:10 +1000 (EST)
Thanks Dustin. I think now I'll be going places. But
before
I go away and play with this, note that my data was
produced for
a mac and is in the form of "\$BYTEORD\4,3,2,1" .
Also, the data I'm trying to read is "a 10-bit
number.....stored in 16-bit space.......leaving 6
empty bits"
Does this mean that I need to include a bitmask? Do
you know
how to do that?
Nick
--- Dustin Voss <email@hidden> wrote:
> On 30 May 2005, at 3:51 PM, Nicholas Crosbie wrote:
>
> > The data "is a continuous bit stream with no
> > delimiters", sent in the form of unsigned binary
> > integer. I'm attaching the data segment. It looks
> > binary to me - at least, it's a pile of
> hieroglyphics
> > when opened in a text editor.
>
> It's a good thing I spoke up, then. You should not
> be using NSString.
> You need to know the endian-ness and size of the
> integers. They could
> be 1-byte, 2-byte, 4-byte, or 8-byte, and
> little-endian or big-
> endian. Looking at the file in a hex editor, it
> looks like 2-byte
> little-endian integers, almost entirely less than
> 768.
>
> > I thought first to use NSData; however, NSData's
> > deserialize methods (which, to the newbie, look
> like
> > they might help me to convert the data to a human
> > readable form - but perhaps I'm way of track) are
> > deprecated in Tiger. So how would I make proceed
> if
> > using NSData?
>
> A good way to handle binary data is to treat NSData
> as if it holds an
> in-memory C data structure.
>
> An undelimited series of unsigned 2-byte integers
> looks just like a C
> array of UInt16. A C array is just a pointer to the
> first element of
> the array, with some friendly syntax to access other
> elements. So do
> this:
>
> const UInt16 *intStream = (const UInt16 *)[fileData
> bytes];
> int intCount = [fileData length] / sizeof(UInt16);
>
> You can access each element of the array with
> intStream[0], intStream
> [1], etc., and it will work out right.
>
> The only other thing to watch out for is
> endian-ness. The elements
> may have the structure of a UInt16 array, but unless
> you correct the
> endian-ness, the elements won't have the correct
> values. So, for each
> element, do this:
>
> UInt16 realValue = CFSwap16LittleToHost
> (intStream[i]);
>
> This will make the little-endian 2-byte integers
> right for the Mac.
>
Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden