The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: problem in reading large deimal number
Replies: 1   Last Post: Jul 17, 2013 9:41 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 2
Registered: 7/17/13
problem in reading large deimal number
Posted: Jul 17, 2013 2:06 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


my main intention to convert decimal number to IEEE 754 form.
so for that conversion i am going to use below function
function s = num2bin(x)
s = sprintf('%bx',x);
t = sprintf('%bx',2);
if t(1)==0
s = reshape(fliplr(reshape(s,2,8)),1,16);
s = reshape(dec2bin(hex2dec(s'),4)',1,4*16);

function calling
fid = fopen('decimal.txt','r');
x = fscanf(fid,'%f',1)
y = num2bin(x)

where x will be decimal no.
which i am going to read from a file
this function works fine if decimal number is small
if it is large like this
then it x is truncating
this i dont want because i am loosing precision
if i gave %d in scanf then it gives
this i don't want

i tried by giving %s while scanning it scan whole value as it is
but then there is problem in num2bin function because sprintf gives wrong value for that

num2bin function works fine for such a large number because when i am direction giving such a large number as input to num2bin function it works very fine

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.