flat assembler
Message board for the users of flat assembler.

 Index > DOS > convert exponent(binary) to decimal
Author
mns

Joined: 20 Dec 2007
Posts: 116
Location: Piliyandala,Sri lanka
mns
this may be a silly question, but please bear with me.
when converting single(or double) precision number to decimal(and print it on the screen),i used following method(of course with the help of the people in this forum in another topic)

read the sign bit ------> print - or keep empty
read mantissa bits ----------> convert to decimal (using helps i got for the last topic)
so mantissa = 0.mmmmmmmm......
calculate the exponent(E) ------> E = bE - 127(in single precision)
convert E(which is in binary) to decimal exponent so 2^E ---------> 10^n
using,
log 2 Val = log 10 val / log 10 2
so log 10 val = log 2 Val x log 10 2
so n = log 2 Val x log 10 2

n will be in the format like,
n = y.zzzzzzzzz...

so decimal number will be
(1.mmmmmmmm.... x 10^0.zzzzzzzzz...) x 10^y

but my problem is how to perform 1.mmmmmmmm.... x 10^0.zzzzzzzzz part.

really appreciate if some one can help on this or show another way of convert single( or double)precision number to decimal string.thanks.
13 Jun 2015, 16:43
El Tangas

Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas
I suppose the most difficult is to calculate 10^0.zzzzzzzz. To do this, note that 10^0.zzzzzzz is z1*10^1/2*z2*10^1/4*z3*10^1/8*z4*10^1/16*.... so you can have the roots of 10 hardcoded, and multiply them according to the bit pattern in 0.zzzzzzzzz.
13 Jun 2015, 19:43
mns

Joined: 20 Dec 2007
Posts: 116
Location: Piliyandala,Sri lanka
mns
sorry El Tangas, i still cannot understand.
when convert to binary exponent to decimal exponent(n)
.zzzzzzzz will be a decimal number. for example it can be .457733... and will bit pattern of it work ?

also,when using
log 10 val = log 2 Val x log 10 2
is the result in the single precision format? if so, things will get more complicated.
and now i really confused
14 Jun 2015, 02:16
El Tangas

Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas
Well, a number is a number, it doesn't matter if it's represented in binary or decimal. You want to to convert a mantissa suitable for exponents of 2 (that we can call binary) to a mantissa suitable for exponents of 10 (that we can call decimal), but these are just labels we can use for convenience. Both are just numbers. The binary representation will work.
You can do the operations in the FPU or use some custom fixed point format and do them with integer operations, you have to decide the exact implementation, probably will not be easy.
14 Jun 2015, 09:06
RIxRIpt

Joined: 18 Apr 2013
Posts: 50
RIxRIpt
14 Jun 2015, 09:25
mns

Joined: 20 Dec 2007
Posts: 116
Location: Piliyandala,Sri lanka
mns
thank you
RIxRIpt, the calculator source is bit hard to understand.since it is one of the few examples on converting real to decimal that i could find, i have to understand it anyway.thanks again.
14 Jun 2015, 18:03
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum