Sign in to follow this  
KorangarDev

Weird simple CSharp math issue.

Recommended Posts

I have a weird bug!
The line
[CODE]
Console.WriteLine(2^32);
Console.WriteLine((uint)2^32);
[/CODE]
both show the result is 34...
And that's basically my entire program.

I ran a loop for each possible number for i from 32 down and did 2^i.
34
29
28
31
30
25
24
27
26
21
20
23
22
17
16
19
18
13
12
15
14
9
8
11
10

Thoughts?

Share this post


Link to post
Share on other sites
What are you expecting it to return? Are you thinking that ^ is a power operator (it's not)?

See here for c# operators: [url="http://msdn.microsoft.com/en-us/library/6a71f45d.aspx"]http://msdn.microsof...y/6a71f45d.aspx[/url]

Share this post


Link to post
Share on other sites
Note that exponential is generally written ** (double asterisk) in programming languages, if it is defined at all (Python supports it, for instance).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this