看下面一段代码:
#include "stdafx.h"int main()
{
int nNumColors = 1<<8;
printf("nNumColors=%d\n",nNumColors);
return 0;
}按照我做法,输出nNumColors=8*2=16;
然而,编译器输出nNumColors=2的8次方=256;
请各位指点,是我的思路错了,还是编译器错了? 谢谢!!
#include "stdafx.h"int main()
{
int nNumColors = 1<<8;
printf("nNumColors=%d\n",nNumColors);
return 0;
}按照我做法,输出nNumColors=8*2=16;
然而,编译器输出nNumColors=2的8次方=256;
请各位指点,是我的思路错了,还是编译器错了? 谢谢!!
怎么结果变为256 呢?
应该是8<<2才能实现
应该是8<<1就可以了。
其实就是 00000000 00000001 往左边推8次.
你再把它转成10进制,看看是不是256.