Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an ASCII character into an int in C

Tags:

c

ascii

character

How can I convert an ASCII character into an int in C?

like image 257
node ninja Avatar asked Mar 16 '11 07:03

node ninja


People also ask

Can we convert a character to integer in c?

We can convert char to int by negating '0' (zero) character. char datatype is represented as ascii values in c programming. Ascii values are integer values if we negate the '0' character then we get the ascii of that integer digit.

How do I convert ASCII characters?

Very simple. Just cast your char as an int . char character = 'a'; int ascii = (int) character; In your case, you need to get the specific Character from the String first and then cast it.


1 Answers

What about:

int a_as_int = (int)'a'; 
like image 90
rjnilsson Avatar answered Oct 12 '22 22:10

rjnilsson