多字节整数变量用C [英] Multibyte Integers Variables in C

查看:237
本文介绍了多字节整数变量用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如何计算在单引号的字符串整数值

I'd like to know, how to calculate integer values of strings in single quotes ' '.

我的示例code是:

#include <stdio.h>

int main()
{
    int c = 'aA';
    int d = 'Aa';

    printf( "%d %d" , c, d);

    return 0;
}

和输出是:

24897 16737

什么是这些数字?有没有什么公式来计算呢?

What are those numbers? Is there any formula to calculate them ?

推荐答案

它们是:


  1. 不是字符串!

多字节整数,其值是实现定义,但它通常是使用以下公式计算:

multibyte integers, of which the value is implementation-defined, but it is usually calculated using this formula:

整数(2';&LT; CHAR_BITS)+第2个字符的整数值

因此​​,假设你的C语言环境使用ASCII和你有8位字节,'AA'变为

So, assuming your C locale uses ASCII and you have 8-bit bytes, 'aA' becomes

97 * 256 + 65

这是24897。

which is 24897.

多字符文字是类型 INT

这篇关于多字节整数变量用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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