Binary to decimal in c

后端 未结 5 629
Happy的楠姐
Happy的楠姐 2020-12-19 20:51

I have a simple code to convert binary to decimal numbers. In my compiler, the decomposition works just fine for number less than 1000, beyond the output is always the same

5条回答
  •  被撕碎了的回忆
    2020-12-19 21:41

    Most likely this is because you are using an int to store your binary number. An int will not store numbers above 2^31, which is 10 digits long, and 1023 is the largest number you can get with 10 binary digits.

    It would be much easier for you to read your input number as a string, and then process each character of the string.

提交回复
热议问题