Converting bits to decimal

Hi.
I'm writing a program(header file) that represents big floating point numbers (50 bits for exponent and 450 bits for mantissa)
I have a problem with converting bits to decimal.
I know its mathematical method but how can I e.g. calculate 2^(-200) ?
(for showing digits in base 10 as output)

Thanks
It's for this very reason that most arbitrary precision software performs its calculations using the same format that will be used for output (e.g. using base 10 integers).

(That wasn't very helpful, sorry.)
Last edited on
But cout does that, so there must be a really simple way.
I was thinking in a table where you have the representation of the binary digits (BCD table), and you do the conversion but operating in binary mode.
Something like:
0000 "0"
0001 "1"
0010 "2"
0011 "3"
//...

For integers
1
2
3
4
5
void BCD(int n){
   if(n==0){ cout<<"0"; return;}
   BCD( n/'1010b' );
   cout<< table[ n%'1010b' ];
}
RE: ne555


I can't understand what you say.
To which number I should write that table ?

I can't understand your code. Please explain more.

Thanks
I just was guessing how cout works.
The table is the correspondence of binary code and the ten digits of the decimal system (0000->"0" to 1001->"9" )
Like if you want to convert (manually) from decimal to hexadecimal you need to know that 10->"A", 11->"B" ... 15->"F"

But you've got a number that is greater to 1001b, so you need to calculate a conversion.
Suppose you want to convert from base 10 to base 2. You keep dividing by 2 until your result is zero and put the modules in inverse order.

Now to pass from base 2 to base 10, you add the positions that have a '1' (multiply by the respective power)
Instead of that my guess is: "To convert from base 2 to base 10, keep dividing by 1010b (10d) until your result is zero and put the modules in inverse order (that's why you need the table). doing the operations in base 2"

By instance suppose you want to print 101010b
101010 / 1010 = 100 remainder 10 -> "2"
100 / 1010 = 0 remainder 100 -> "4"
"42"
Last edited on
!!?
Topic archived. No new replies allowed.