菜鸟求解
c++吧
全部回复
仅看楼主
level 1
btt1095347198 楼主
int a = 0x1;
a = a << 33;
cout << a;
结果为啥为2呢??
2012年08月08日 03点08分 1
level 1
btt1095347198 楼主
还有一个int b = 0x80000000;
b = b << 33;
结果为啥为0
2012年08月08日 03点08分 2
你这个b显然溢出了。不存在0X80000000。你可能想赋给b的值是-1吧。 b=0XFFFFFFFF。这才是-1
2012年08月08日 09点08分
回复 潮流刺客 :呵呵,我想赋给b的就是0x80000000,是负的最小值,哪溢出了啊。[$1]我也是知道 b=0XFFFFFFFF,的结果为-1啊。
2012年08月10日 09点08分
intel的移位操作是用的摸算术和我们的常规直觉有区别,貌似 a << 33 执行的是 a << (33 % 32)
2012年09月03日 02点09分
level 7
反汇编分析下
2012年08月08日 03点08分 3
level 7
2012年08月08日 03点08分 4
反汇编只能看到结果吧,我想知道。左移31位后a为多少
2012年08月08日 03点08分
回复 @btt1095347198 :主要是过程
2012年08月08日 03点08分
回复@btt1095347198 : 0x80000000
2012年08月08日 03点08分
回复 @btt1095347198 :貌似32位机,int类型 左移33位=左移1位 1当然变成二进制的10 就是2
2012年08月08日 03点08分
level 7
a = a << 33;
warning C4293: “<<”: Shift 计数为负或过大,其行为未定义
2012年08月08日 03点08分 5
level 7
对于Release版本,这个数值是0.
2012年08月08日 03点08分 6
shl eax, 21h 不会把eax清空么。。。
2012年08月08日 03点08分
回复@风之追梦者 : 按常理说是这样的,但shl真的没有清空。我也不知道为什么。倒像是把21h当成了1h来处理。
2012年08月08日 03点08分
常理来说,这两个值都应该是0吧。但<<33位为什么按<<1来算了呢?? 是因为这个原因吗?? Shift 计数为负或过大,其行为未定义
2012年08月08日 04点08分
这是今天的面试题,居然这么坑底
2012年08月08日 04点08分
level 1
btt1095347198 楼主
顺便问一句啊,socke的listen方法允许的最大排队等待长度是多少??
2012年08月08日 04点08分 7
level 7
@傲娇so_good
@风之追梦者
看这里:
Description
Shifts the bits in the first operand (destination operand) to the left or right by the
number of bits specified in the second operand (count operand). Bits shifted beyond
the destination operand boundary are first shifted into the CF flag, then discarded. At
the end of the shift operation, the CF flag contains the last bit shifted out of the destination
operand.
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.
上述参考说明:
32 bit 环境下:
“The count is masked to 5 bits, The cout range is limited to 0 to 31.”
在因特尔指令编码里,计数器为5bits,自然是0-1Fh,而imm8是8bits,所以大于31的数都会“环绕”。而且对移动一位的情况有特殊编码。
2012年08月08日 05点08分 8
那你所说的Release模式是0又是什么情况呢???
2012年08月08日 05点08分
回复@风之追梦者 : Release是被编译器优化过的,根本不存在shl指令,编译器按照标准C++语法预测了结果,直接将0作为参数给了cout重载的“operator <<”。
2012年08月08日 05点08分
回复 @win2446 :那罗哈多。。。
2012年08月08日 05点08分
回复@风之追梦者 : “那罗哈多”是神马意思?[思考]
2012年08月08日 05点08分
level 9
mod32
2012年08月08日 09点08分 9
1