Even though, how would one print a self-made big integer value? |
If the numbers is really a binary number then you have to do it the same way as with smaller numbers: divide by 10, take the remainder, lather rinse repeat.
Or to avoid the division:
- start with tmp=1
- Multiply by 10 until tmp>n
- Take the previous value of tmp and
- repeatedly subtract tmp from n until n< tmp. Count the number of times you subtract
- print that number.
- repeat.
For example, to print 467:
- tmp=1
- keep multiplying until tmp=1000
- take previous value: tmp=100
- subtract : 467-100-100-100-100 = 67
- print 4 (the number of times you subtracted.
- repeat to process to print 67.
The other option is to not store the numbers in binary in the first place. For example, you might store it in base 1,000,000,000 where each 32-bit value stores a base 1 billion digit. This makes the arithmetic a little more complex but printing it gets much easier.
That can be extended all the way down to binary-coded decimal where you store a single base-ten digit in a 4 but field. With this method, arithmetic is hard by printing is trivial.