Delphi to C Builder’s conversion

I have source code in Delphi. I follow this http://hscripts.com/tutorials/cpp/bitwise-operators.php to convert it in C Builder for bitwise operators, 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 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 &amp ;.

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 &amp ;.

Try:

tmp = ((dynamicINT << 1) | (dynamicINT >> 31) & 0x7FFFFFFF);

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3161 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.