How to convert decimal to IEEE double precision floating point binary in Matlab?

user2045143

I am trying to generate an MIF file for FPGA synthesis and I am programming in Matlab to do it.

I want numbers ranging from -1 to 1 (-.9,-.8,-.7...1) in IEEE standard double precision floating point so that I can write it onto an MIF file an use in Verilog. Are there any Matlab functions to do this in an easy way? Thanks for any suggestion in advance.

nispio

Try this:

oldFormat = get(0,'Format');
format('hex'); display( -1:0.1:1 );
format(oldFormat);

Only the middle line is important. The other two just put your format back to what it was before ('short' by default). I don't know for certain that the output conforms to IEEE, but I suspect it will. According to the documentation this will display a "Hexadecimal representation of a binary double-precision number."

If you want to save them as strings you could print later use sprintf with format %bx:

x = -1:0.1:1;
for i = 1:length(x)
    vals{i,1} = x(i);
    vals{i,2} = sprintf('%bx',x(i));
    vals{i,3} = dec2bin(hex2dec(sprintf('%bx',x(i))),64);
end
display(vals(:,[1 2]));
display(vals(:,3));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How does JavaScript runtime convert BINARY (Double-precision floating-point format) back to DECIMAL

Python generate IEEE 754 double-precision binary floating-point format

How many integers divisible by 2 can be represented in IEEE-754 floating point with double precision?

unexpected behavior for the decimal places while convert a Double to a Float value (floating-point precision) using BigDecimal and DecimalFormat

How do I convert a hexadecimal number in IEEE 754 double precision (64bit) format to a decimal number?

Over what range will integer arithmetic addition and subtraction be accurate to the integer in IEEE double precision floating point?

safely round-trip integers values with IEEE 754 floating point double precision data type

How to convert binary floating points to decimal fractions?

How do we need 17 significant decimal digits to identify an arbitrary double-precision floating-point number?

Python program to convert Hexadecimal to IEEE-754 Floating Point with Single precision

Decimal Floating Point to Binary Conversion

How accurate is "double-precision floating-point format"?

convert single precision floating point to half precision floating point

What is the definition of Convert_Single_Precision_To_Double_Precision_Floating_Point() in the Intel software developer manuals?

Determining decimal precision of a floating point number

Decimal to half-precision floating point

Convert binary 32bit IEEE-754 floating points to Double in .net

Convert decimal to binary in Matlab?

converting c# float to IEEE single precision floating point bytes

Double floating-point precision in Java

Matlab "single" precision vs C floating point?

Decimal to binary Half-Precision IEEE 754 in Python

Converting IEEE-754 double and single precision to decimal Java bug

How does computer convert floating point numbers to decimal string?

How to convert floating point decimal separator from dot to comma in Javascript

How to Convert a parseFloat string number to a floating point with 2 decimal places

Converting a decimal number to floating point notation and IEEE 754 format

Converting from decimal to IEEE 8-bit floating point representation

Conversion of decimal floating point numbers to binary and back