wierd answer at end of program

i am trying to make a program that will convert a whole number to binary... it works well from the groups of numbers I have tested until you reach 1024. when you use 1023 it works fine and when you use 1024 it works fine until the very last cycle through. 1024 seems odd because of its relation to a unit of storage on a computer. Am I just not aware of a certain limitation, maybe?


here is a link to the code I have used. http://codepad.org/IJ7pS2hP
Last edited on
1023 is 11 1111 1111, or in decimal representation, 1,111,111,111
1024 is 100 0000 0000, or 10,000,000,000

1,111,111,111 is lower than 2^31-1, the limit for a 32-bit signed integer (int), but 10,000,000,000 is more than four times that value.

When converting to binary, put the result in a string or an array, not an integer.
Last edited on
Topic archived. No new replies allowed.