我在Delphi中有源代码我按照这个 http://hscripts.com/tutorials/cpp/bitwise-operators.php为按位运算符在C Builder中转换它,但结果是不同的 Delphi中的源代码 procedure TForm1.Button1Click(Sender: TObject)var tmp,
Delphi中的源代码
procedure TForm1.Button1Click(Sender: TObject) var tmp, dynamicINT : integer; begin dynamicINT := 42080; tmp := ((dynamicINT shl 1) or (dynamicINT shr 31) and $7FFFFFFF); Edit1.Text := IntToHex(tmp, 4); end;
德尔福结果:148C0正确!
C Builder中的源代码
void __fasctall TForm1::Button1Click(TObject *Sender) { int tmp = 0; int dynamicINT = 42080; tmp = ((dynamicINT << 1) || (dynamicINT >> 31) && 0x7FFFFFFF); Edit1->Text = IntToHex(tmp, 4); }
C Builder结果:0001 ???
转换有什么问题?
我正在使用C Builder 6和Delphi 7
||和&&是C中的逻辑运算符,而不是按位运算符.它们只返回true / false.相应的二元运算符是|和& ;.尝试:
tmp = ((dynamicINT << 1) | (dynamicINT >> 31) & 0x7FFFFFFF);