Get ASCII value at input word

后端 未结 6 1244
心在旅途
心在旅途 2020-12-01 13:59

I have a character:

 char ch=\'A\'

Give me method which converts char to ASCII
or way which returns a ASCII NUMBER

6条回答
  •  佛祖请我去吃肉
    2020-12-01 14:45

    A char is actually a numeric datatype - you can add one to an int, for example. It's an unsigned short (16 bits). In that regard you can just cast the output to, say, an int to get the numeric value.

    However you need to think a little more about what it is you're asking - not all characters are ASCII values. What output do you expect for â, for example, or ?

    Moreover, why do you want this? In this day and age you ought to be thinking about Unicode, not ASCII. If you let people know what your goal is, and how you intend to use this returned value, we can almost certainly let you know of a better way to achieve it.

提交回复
热议问题