Pages

August 18, 2013

Hex to Int number conversion

Hexadecimal-to-NSInteger made easy with this helpful function.


/** Convert a hex to an int.

 @param val Hexadecimal value as string.
 @return Returns the integer value.
 @see isHexadecimalNumber:
 @see hexFromInt:

 */
+ (NSInteger)intFromHex:(NSString *)val {
    NSUInteger res = 0;
    NSScanner *scanner = [NSScanner scannerWithString:val];
    [scanner scanHexInt:&res];
    return (NSInteger)res;
}



Download the ready-for-use source file (.m) of Hex to Int number conversion

No comments:

Post a Comment