2

How can I conver it into 192 as integer value?

NSString* hex = @"c0"; 

Or I have char a1 = **'\xc0';** How do I convert it into int? I cant use atoi in Xcode. :(

Thanks

1 Answer 1

2

You have two choices, a C style one and an Objective-C one, first one is something like

long value = 0; sscanf_s([hex cStringUsingEncoding:NSUTF8StringEncoding], "%x", &value); 

Latter is something like

long value = 0; NSScanner *scanner = [NSScanner scannerWithString:hex]; [scanner scanHexInt:&value]; 
Sign up to request clarification or add additional context in comments.

1 Comment

I recently started developing for a Bluetooth device and couldn't figure out how to properly pass the string representation of my hex values. Haven't heard of the NSScanner class until now, so thank you! This is the answer, it works as intended.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.