• Advertisement
Sign in to follow this  

Weird simple CSharp math issue.

This topic is 2129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a weird bug!
The line

Console.WriteLine(2^32);
Console.WriteLine((uint)2^32);

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
Advertisement
No bug, it is a bitwise operator (XOR), so it is doing exactly what it is suppose to be doing.

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
Sign in to follow this  

  • Advertisement