Re: Hex <=> NSNumber?
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