half an int
Hello all, just a quick quest:
is half an unsigned int 0x80000000 or 0x7FFFFFFF?
0xFFFFFFFF / 2 = 0x7FFFFFFF
0x7FFFFFFF * 2 = 0xFFFFFFFE
(note the trailing E)
0x80000000 * 2 = 0x0 (or more exactly 0x100000000 (9 digits))
I opt for 0x7FFFFFFF (as 2 * the half shouldnt be 0!)
Any comments or thoughts?
would be "half" of an unsigned 32 bit integer, though "half" is a rather silly term for it. A 32 integer holds an even number of values, but you have to remember that the values start at 0 not 1, so dividing directly by 2 will give you a fraction. What you'd do is divide 2^32 by 2 and then subtract 1 from it to get "half" full. Since the "value" of 0xFFFFFFFF is odd, you can't multiply an integer by 2 to get it.
The reason you are getting 0 for 0x80000000 * 2 is because that goes 1 over the maximum amount that a 32 bit integer can hold. The numbers "rolled over" back to 0.