Re: Two Questions on NSStrings <-> bytes
Re: Two Questions on NSStrings <-> bytes
- Subject: Re: Two Questions on NSStrings <-> bytes
- From: Jaime Magiera <email@hidden>
- Date: Mon, 22 Oct 2007 13:13:44 -0400
On Oct 22, 2007, at 12:54 PM, Alastair Houghton wrote:
You're probably over-thinking it. That's the usual reason for
problems like this.
=)
It doesn't make sense for an eight-bit value to be Big Endian (or
Little Endian).
Sorry, yes, I meant the overall file requires Big Endian values (.mov
and .m4a)
Anyway, I'm unclear what you need here (and I think the reason is
that *you're* unclear what it is that you need). Do you want a
binary value? Or an ASCII string consisting of two hexadecimal
digits?
If you need binary, e.g. in an NSData, all you need do is:
Ok, my problem here was something simple... I wasn't casting the
[NSString length] to a int8_t. The following worked...
int8_t chapterURLSizeValue = (int8_t)[chapterURL length];
data3 = [NSMutableData dataWithCapacity:1];
[data3 appendBytes:&chapterURLSizeValue length:1];
What do you want here?
Here is the spec. The items I'm working on are URLLength and URL
class TextHyperTextBox() extends TextSampleModifierBox (‘href’) {
unsigned int(16) startcharoffset;
unsigned int(16) endcharoffset;
unsigned int(8) URLLength;
unsigned int(8) URL[URLLength];
unsigned int(8) altLength;
unsigned int(8) altstring[altLength];
}
In a test file created by GarageBand, the binary output looks like so
using xxd...
02facd: 00085072 6f664361 73740000 00256872 ..ProfCast...%hr
002fadd: 65660000 00081768 7474703a 2f2f7777 ef.....http://ww
002faed: 772e7072 6f666361 73742e63 6f6d00 w.profcast.com.
So, I need to convert an NSString value of something like "http:///
www.apple.com", to a straight c-string and write that out. I've tried
a lot of different ways, but I keep ending up with lots of binary
0's. I think there is something fundamental about bytes/characters/
etc. that I don't get.
Well, it depends exactly what it is that you want to learn. A good
place to start, for lower-level things like bytes, would be
learning plain, vanilla C (not C++, Cocoa, C#, Java or anything
like that, as tutorials in those languages tend either to assume
that you know C, or try to skirt around the issue entirely). It
sounds like you might also want to take a good look at the whole
area of character encoding, so that you understand why the results
you show above are as they are... you might start by taking a look
at ASCII: <http://en.wikipedia.org/wiki/ASCII>
Excellent. Thank you.
Jaime Magiera
Sensory Research
http://www.sensoryresearch.net
_______________________________________________
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