c++ - C语言中各类型数表示范围
PHPz
PHPz 2017-04-17 13:04:20
0
2
538


我知道在limit.h文件里有对应的类型所能表示的最大最小的范围,例如如下程序.

void printlimits()
{
    printf("signed char min=%d\n",SCHAR_MIN);
    printf("signed char max=%d\n",SCHAR_MAX);
    printf("signed short min=%d\n",SHRT_MIN);
    printf("signed short max=%d\n",SHRT_MAX);
    printf("signed int min=%d\n",INT_MIN);
    printf("signed int max=%d\n",INT_MAX);
    printf("signed long min=%ld\n",LONG_MIN);
    printf("signed long min=%ld\n",LONG_MAX);
    printf("unsigned char max=%u\n",UCHAR_MAX);
    printf("unsigned short max=%u\n",USHRT_MAX);
    printf("unsigned int max=%u\n",UINT_MAX);
    printf("unsigned long max=%lu\n",ULONG_MAX);
    
}

在图片上的这个方法~0>>1,如果是8位的话变成,11111111,然后右移移位,变成01111111,转换成负数后应该再减去1才是能表示的最小数吧?
数上直接这么写的,难道有什么玄机呢
8位不是-128-127吗?

PHPz
PHPz

学习是最好的投资!

reply all(2)
左手右手慢动作

Please check the assembly code directly

大家讲道理

Sorry, I didn’t see the question clearly. Then let me explain it to you now, ~0>>1 is followed by 0111 1111. At this time, it is an unsigned number, and then it is converted into a signed number without changing 0111 1111. The complement representation means that because it is a positive number, it is 127 after taking the negative Do you think it should be -128?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!