本帖最后由 wsfxzxb 于 2013-02-21 12:05:38 编辑

解决方案 »

  1.   

    1《x 是1 左移多少位
       1《3 左移三位 结果为1000 是8
    iColors 是什么类型?
      

  2.   

    Colors =1 << (iPlanes * iBitsPixel) 编译后是SHL指令,SHL指令在IA32上只考虑移位操作数的低5位,
    也就是SHL 1,32机器指令的执行等同于SHL 1,0(32的mask低5位就是0),所以表达式等价于Colors = 1 << 0 结果为1iColors = 1<<32在编译时编译器帮你计算1<<32的结果为0,所以iColors 编译后初始化为0
      

  3.   


    均是错误的, 超过int本身的宽度或者等于宽度,是未定义行为, 移位是错误的。改成:INT64 iColors=(INT64)(1)<<(32);试试, 可以获得你的计算机的色彩色。貌似是理论色彩啊
      

  4.   

    SHL指令在IA32上只考虑移位操作数的低5位从未听说这条指令是这样的,你贴书本的解释。。
      

  5.   

    The destination operand can be a register or a memory location. The count operand 
    can be an immediate value or the CL register. The count is masked to 5 bits (or 6 bits 
    if in 64-bit mode and REX.W is used). The count range is limited to 0 to 31 (or 63 if 
    64-bit mode and REX.W is used). A special opcode encoding is provided for a count 
    of 1.--<<[Intel]Instruction Set Reference, A-Z (Volume 2)>>
      

  6.   


    说明这种指令最多可以31次移位
     超过int本身的宽度或者等于宽度,是未定义行为, 移位是错误的。
     
      

  7.   

    谢谢大家指导。
    请问2楼:这个是不是只针对变量,而不针对常量?
    请问3楼:现在可以出正确结果了。INT 64是指什么? 8 个字节长的整形,它的取值范围是?
      

  8.   

    primer里没说只是变量INT64是windows里的数据类型