This discussion is archived
2590 Views 7 Replies Latest reply: Mar 18, 2009 1:25 PM by iamravenous
Currently Being ModeratedOct 30, 2008 5:25 PM (in response to fireman888)I believe something like the following should work...
int intValue = 255;
NSString *hexValue = [NSString stringWithFormat:@"%02x", intValue];
If I remember my formatting codes correctly, that is... (note this assumes that you're dealing with a value from 0 - 255 as it will zero pad to two spaces)
rob.Macbook Pro 2.33, Mac OS X (10.5.2)
Currently Being ModeratedJan 27, 2009 4:52 AM (in response to fireman888)This problem is in a class of problems called NPC (http://en.wikipedia.org/wiki/NP-complete), but don't worry yourself about this. Your problem can still be solved with the following BSD code:
This file is part of libaltivec. sscanf implementation.
Copyright (C) 2003. Red Hat, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sscanf (const char *string, const char *format, ...)
va_start (ap, format);
result = vsscanf (string, format, ap);
}Toaster, Other OS, I'm working on my latest screenplay.
Currently Being ModeratedMar 18, 2009 1:25 PM (in response to fireman888)
Hi, how can I conver number to a hex string?
For exmple convert 255 to "FF"?
Thank you very much.
NSString *c = @"FF";
unsigned int h;
[[[NSScanner scannerWithString:c] scanHexInt:&h]];Mac OS X (10.5.6)