看下面一段代码:
#include "stdafx.h"int main()
{
    int  nNumColors = 1<<8;
printf("nNumColors=%d\n",nNumColors);
return 0;
}按照我做法,输出nNumColors=8*2=16;
然而,编译器输出nNumColors=2的8次方=256;
请各位指点,是我的思路错了,还是编译器错了? 谢谢!!

解决方案 »

  1.   

    <<  是左移运算符  即1<<; 向做移动1位,则8*2=16;
    怎么结果变为256 呢?
      

  2.   

    你那是1左移8位,而不是8左移1位8<<1
      

  3.   

    1 <<8表示1向左移8位,相当于1乘以2的8次方。
      

  4.   

    8*2=16;
    应该是8<<2才能实现
      

  5.   

    8*2
    应该是8<<1就可以了。
      

  6.   

    一个int类型是4字节.
    其实就是 00000000 00000001 往左边推8次. 
    你再把它转成10进制,看看是不是256.