I have source code in Delphi I follow this http://hscripts.com/tutorials/cpp/bitwise-operators.php for bitwise operators to convert it in C++ Builder, but the result is different
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 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 is wrong with conversion ?
I'm 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);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With