flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > DOS > convert exponent(binary) to decimal

Author
Thread Post new topic Reply to topic
mns



Joined: 20 Dec 2007
Posts: 98
Location: Piliyandala,Sri lanka
convert exponent(binary) to decimal
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......
read biased exponent bits(bE)
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.
Post 13 Jun 2015, 16:43
View user's profile Send private message Send e-mail Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
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.
Post 13 Jun 2015, 19:43
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 98
Location: Piliyandala,Sri lanka
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
Confused
Post 14 Jun 2015, 02:16
View user's profile Send private message Send e-mail Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
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.
Post 14 Jun 2015, 09:06
View user's profile Send private message Reply with quote
RIxRIpt



Joined: 18 Apr 2013
Posts: 49
Post 14 Jun 2015, 09:25
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 98
Location: Piliyandala,Sri lanka
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.
Post 14 Jun 2015, 18:03
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.