如何将 ASCII 字符转换为其 ASCII 整数值? [英] How to convert an ASCII char to its ASCII int value?

查看:45
本文介绍了如何将 ASCII 字符转换为其 ASCII 整数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个字符转换为它的 ASCII int 值.

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'.

重点是 atoi() 在这里不起作用,因为它仅适用于可读数字.

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

它不会对空格(ASCII 32)做任何事情.

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

推荐答案

这样做:-

char mychar = 'k';
//and then
int k = (int)mychar;

这篇关于如何将 ASCII 字符转换为其 ASCII 整数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆