如何获取字符串的ASCII

gio*_*ozh 3 c unix casting

我需要通过char获取字符串char的ascii(int和hex格式)表示.例如,如果我有字符串"你好",我会得到int ascii 104 101 108 108 111 和为hex 68 65 6C 6C 6F

cni*_*tar 7

怎么样:

char *str = "hello";

while (*str) {
    printf("%c %u %x\n", *str, *str, *str);
    str++;
}
Run Code Online (Sandbox Code Playgroud)

  • 无论如何,一切都以二进制形式存储.不同之处在于您选择如何显示它们. (3认同)