• 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: Converting four char code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting four char code


  • Subject: Re: Converting four char code
  • From: Eric Blairs <email@hidden>
  • Date: Mon, 10 Feb 2003 23:21:56 -0500

On 2/11/03 at 1:37 PM, Greg Hulands <email@hidden> wrote:

>Hi,
>Can anyone tell me how to convert a four-char code into 4 chars?
>
>eg.
>
>'APPL' into 'A' 'P' 'P' 'L'
>
>
I've seen a number of these floating around, but the one I got in some of my
code is from Andrew Stone's Cocoa Files:

- (NSString *)stringFromCode:(unsigned long)code {
unsigned char c[5];

c[0] = code >> 24;
c[1] = (code >> 16) & 0xff;
c[2] = (code >> 8) & 0xff;
c[3] = code & 0xff;
c[4] = '\0'; // don't forget to terminate the cstring!

return [NSString stringWithCString:c];
}

and the corresponding function, just for the sake of completeness

- (unsigned long)codeFromString:(NSString *)fourLetterWord {
unsigned const char *c = [fourLetterWord cString];

if ([fourLetterWord cStringLength] == 4) {
return ((c[0]<<24) + (c[1]<<16) + (c[2]<<8) + c[3]);
}
return 0;
}

<http://www.stone.com/The_Cocoa_Files/Crossing_the_Line.html>

I'm not using the latter function, but the former seems to be working properly
for me.

--Eric
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Converting four char code (From: Greg Hulands <email@hidden>)

  • Prev by Date: NSFont and memory management
  • Next by Date: Re: Converting four char code
  • Previous by thread: Converting four char code
  • Next by thread: Re: Converting four char code
  • Index(es):
    • Date
    • Thread