How to get ASCII value for character in Cocoa?

How to get ASCII value as int character in Cocoa? I found the answer for this in python, but I need to know how to do this in Cocoa. (I'm still noob in Cocoa).
Python Method:
use the ord () function as follows:

>>> ord('a') 97 

as well as chr () for another:

 >>> chr(97) 'a' 

How to do it in Cocoa?

+6
c objective-c cocoa ascii
source share
2 answers

Character constants are already integer:

 int aVal = 'a'; // a is 97, in the very likely event you're using ASCII or UTF-8. 

It really has nothing to do with Cocoa, which is a library. This is part of C, so it is not specific to Objective-C.

+12
source share

It has nothing to do with Cocoa, it depends on the language, just in C or C ++ it does the conversion from int to char :)

C ++:

 #include <iostream> int main() { int number; char foo = 'a'; number = (int)foo; std::cout << number << std::endl; return 0; } 
+1
source share

All Articles