Source code in 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;
Delphi result: 148C0 is correct!
Source code in 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 result: 0001 ???
What’s wrong with the conversion?
I am using C Builder 6 and Delphi 7
Try:
tmp = ((dynamicINT << 1) | (dynamicINT >> 31) & 0x7FFFFFFF);
I have Source code I followed this http://hscripts.com/tutorials/cpp/bitwise-operators.php to convert it in C Builder for bitwise operators, but the result is different
Delphi Source code in
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;
Delphi result: 148C0 is correct!
Source code in 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 result: 0001 ???
What’s wrong with the conversion?
I am using C Builder 6 and Delphi 7
|| and && are logical operators in C, not bitwise Operators. They only return true/false. The corresponding binary operators are | and & ;.
Try:
tmp = ((dynamicINT << 1) | (dynamicINT >> 31) & 0x7FFFFFFF);