- #1
YoshiMoshi
- 236
- 10
Homework Statement
So in C an integer is stored as a 32 byte value. Were the 32nd byte is the byte that determines if the value is negative or positive. I created a loop were I set the integer i equal to 1. Each time I cycle through the loop I left shift the variable i by one.
Meaning that the first time through the loop the integer i becomes 10, second time becomes 100. I'm going through a while loop until the variable i becomes negative. Apparently on the 32nd time through the loop I exit the loop. I print the variable i and i get negative 2^(31) power.
Homework Equations
The Attempt at a Solution
[/B]
I don't fully understand this. On the 31st time through the loop I have something like
1000000000000000000000000000000 or positive 2^31
so when I cycle through the loop a 32nd time and left shift the integer i to the left one shouldn't i just get
10000000000000000000000000000000 or negative zero?
Why do I appear to be getting
1100000000000000000000000000000 or negative 2 to the 31 power?
Does the compiler see negative zero as the most negative possible number meaning -2^31? That makes no since to me. When I think of negative zero, it makes no since, and generally think of a very small negative number, meaning I'm approaching zero from the negative side but "never actually reaching zero". Something like negative zero is -0.00000000000000000000001?