And I definitely want to work with number which need more than 63 bits. |
Well, the algorithm itself works for any number of bits, but since I used a
long
to store the decimal value before converting it to a string, it is guaranteed to work only up to 31 bits, since
long
is guaranteed to be at least 32 bits wide (a 32-bit string can represent a value that a
signed long
may not be able to hold. Using
unsigned long
would allow you to use one extra bit but you can't convert negative numbers).
That being said, I guess on most system a
long
is 64 bit now.
I am curious do think converting a binary number that was say 300 bits to decimal is beginners work? |
Probably not, as you most likely need a bigint library to handle data of that width, or a different algorithm than the one I used. And definetly not if you don't want to use any library,
I'm not aware if or how a processor can calculate numbers that are wider than 64 bits, and I can't come up with a good alternative so I can't help you more than this.