• 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: Hex <=> NSNumber?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hex <=> NSNumber?


  • Subject: Re: Hex <=> NSNumber?
  • From: RenĂ© Puls <email@hidden>
  • Date: Thu, 20 Jan 2005 10:48:25 +0100

Hello Dave,

Am 20.01.2005 um 09:12 schrieb Dave DeLong:

Hello everyone,

I'm new to Cocoa, and one of the projects I'm teaching myself on is a color converter application. One of the things I would like it to have is a Hex field. So my question is thus:

How can I take an NSNumber and convert it to it's Hexadecimal equivalent (without having to go through the math myself, and preferably as an NSString)? Likewise, how can I go from Hex to a number?

// NSNumber to hexadecimal NSString:

NSNumber *number;
NSString *hexString;

number = [NSNumber numberWithInt:12345];
hexString = [NSString stringWithFormat:@"0x%x", [number intValue]];

// Hexadecimal NSString to NSNumber:

NSScanner *scanner;
int tempInt;

scanner = [NSScanner scannerWithString:hexString];
[scanner scanHexInt:&tempInt];
number = [NSNumber numberWithInt:tempInt];

Kind regards,
René Puls

_______________________________________________
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


References: 
 >Hex <=> NSNumber? (From: Dave DeLong <email@hidden>)

  • Prev by Date: Re: NSOpenPanel file types & wildcards
  • Next by Date: Re: Authorization without permanent setuid on helper
  • Previous by thread: Hex <=> NSNumber?
  • Next by thread: How to customize Comand +Q handler
  • Index(es):
    • Date
    • Thread