Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delphi to C++ builder conversion

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

like image 838
AkisC Avatar asked Dec 20 '22 14:12

AkisC


1 Answers

|| 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);
like image 51
Mat Avatar answered Dec 24 '22 00:12

Mat