Solved

c# code

Posted on 2008-10-20
3
203 Views
Last Modified: 2013-12-17
there is a small prob with the code converted from vb to c#
---------visual basic ------------
dim j as integer
dim i as integer
for i =0 to 5
j = 2 ^ i    (i being 0 in first time loop)

msgbox(j) returns 1 (ie 2 ^ 0)  

next

==============cSharp========================I want this to return 1 same as in vb

but same code in C# msgbox(j) returns 2
int j = 0;

  for (int i = 0; i < 5; i++)
    {
       j = 2 ^ i;
      Messagebox.show(j); -- j returns 2 (ie  2 ^ 0)

    }
0
Comment
Question by:dotnet0824
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 22756364
Hello dotnet0824,

I believe that the ^ operator is not used in c#, you have to use Math.Power(value,exponent) instead. It is there in VB.net as it is a legacy operator from earlier versions of VB though the Math.Power function works there too!

Regards,

TimCottee
0
 
LVL 19

Expert Comment

by:alb66
ID: 22756752
In C#, ^ is the logical "exclusive or" operator

2 XOR 0 is equal to 2

http://msdn.microsoft.com/en-us/library/6a71f45d(VS.80).aspx
0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 50 total points
ID: 22756764
The correct method to use is Math.Pow(x,y)

http://msdn.microsoft.com/en-us/library/system.math.pow.aspx
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question