How to convert an ASCII char to its ASCII int value?

I would like to convert a char to its ASCII int value.

I could fill an array with all possible values and compare to that, but it doesn’t seems right to me. I would like something like

char mychar = "k"
public int ASCItranslate(char c)
return c   

ASCItranslate(k) // >> Should return 107 as that is the ASCII value of 'k'.

The point is atoi() won’t work here as it is for readable numbers only.

It won’t do anything with spaces (ASCII 32).

Leave a Comment