Link to home
Start Free TrialLog in
Avatar of dotnet0824
dotnet0824

asked on

c# code

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)

    }
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial