Solved

c# code

Posted on 2008-10-20
3
204 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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