1

I am storing color values in a database for an iPad app that needs a legend with colors in it. Each entry has it's own color value, derived from a hex value. Basically, my colors all look like this: 0X######. I have functions that can take this value, as a uint32_t, and turn it into the color I need. However, I store the value as a String.

What I need to do is convert this string to a uint32_t. I need "0X######" to equal 0X######, if that makes sense. I know this might not be possible, in which case I'll have to find another solution.

CrystalBlue
  • 1,793
  • 5
  • 18
  • 27

2 Answers2

2

You can use NSScanner for this.

NSScanner * scanner = [NSScanner scannerWithString:@"0XAABBCC"];
uint32_t val;
[scanner scanHexLongLong:&val];
Joshua Weinberg
  • 28,598
  • 2
  • 97
  • 90
1

I got this code this will worked in my code,

NSScanner * scannered = [NSScanner scannerWithString:colorHex];

    uint32_t scanedVal;
    [scannered scanHexLongLong:(unsigned long long *)&scanedVal];
    NSLog(@"scanner _____%u",scanedVal);
Sandeep Sachan
  • 373
  • 3
  • 15