reset password
Author Message
CSr_esco525
Posts: 15
Posted 11:41 Oct 18, 2016 |

Hello fellow classmates,

I have one question, so on HW7 Problem 5, my program is working on converting decimals to binary, HOWEVER, it can not read really large numbers because of the max capacity of the integer data type. I tried fixing it by separating the string in parts, but got stuck eventually and made the problem even worse with my solutions. Does anyone have any recommendations on how to address the issue with the code?

Thank you.

kknaur
Posts: 540
Posted 11:59 Oct 18, 2016 |

Your code should work for up to the maximum value of the largest integer data type.

CSr_esco525
Posts: 15
Posted 12:44 Oct 18, 2016 |
kknaur wrote:

Your code should work for up to the maximum value of the largest integer data type.

Hello again,

Oh, now I see the problem! I guess it was separating the String in pieces depending on the number after all. Won't that give me a different a value for the binary? For example, the sample integer into binary compared to the sample integer split into pieces:

Integer: 4567876543456789876 -----> Binary:11111101100100010110111000001110111110100101001100010101110100

Integer: 4567 -----> Binary:‭ 0001 0001 1101 0111
Integer: 8765-----> Binary: ‭0010 0010 0011
1101‬

How would the value change in this case?

Thanks.

kknaur
Posts: 540
Posted 13:32 Oct 18, 2016 |

You are overthinking this problem.  You should follow the algorithm for binary to decimal and decimal to binary in the first lecture.