Continue to Site

# conversation of integer or binary value to floating point value

Status
Not open for further replies.

#### itmr

##### Member level 3
hi all
need your help to any idea to convert integer to real number for synthesis

thanks a lot

why would you want to do that?

itmr

### itmr

Points: 2
Do you need to hand the floating point value to a computer subroutine?

The computer must have an internal routine to do its own conversions.

Do you have a list of the internal routines? Can you access them?

itmr

### itmr

Points: 2
Real ís an abstract type used for simulation and compile time calculations only. If you want to represent real numbers in synthesized hardware, use fixed or floating point types. In most cases, IEEE 754 single or double precision formats are used for floating point types. Integer to float conversion is simply a normalization, involving a variable shift operation, not too difficult to implement in HDL. FPGA vendors also have the conversion available with their floating point IP cores.

To solve the said problem, you would rather use a special fixed point format (with scale factor of 1000). If compare is the only thing to do with the input numbers, no conversion is needed at all, the compare can be performed in decimal representation directly.

Consider, that simple pocket calculators restrictect to fundamental arithmetic operations have been often using decimal coded numbers.

I think, you should do part of the exercise yourself.

Last edited:
itmr

### itmr

Points: 2
hi all

trickdicky - i need to convert 6 nuMbers to integer with decimal point in formar XXX.XXX AND THEN COMPER 2 FOLLOWS NUMBERS

FVM - u mean that i need to declear sfixed (2 downto -3) then assign the received integers at the suitable places an multilple it by the scalling factor?

bradtherad - thank u but i mistake - ther is no need for floating point - i can use fixed point with decimal point

---------- Post added at 08:10 ---------- Previous post was at 07:59 ----------

FVM - WHERE type sfixed is array (INTEGER range <>) of STD_LOGIC;

bradtherad - thank u but i mistake - ther is no need for floating point - i can use fixed point with decimal point
In fact, you didn't tell a word about fixed point in this thread yet. That's the bad thing with incomplete questions. Of course, the point would be clearer, if you had managed to avoid cross postings.

sfixed (2 downto -3) can hardly take 6 decimal places. Get your pocket calculator or pencil and paper and try.

It's not clear to me, if a conversion is needed at all. The compare as such can be done for decimal numbers as well, even for an ASCII representation, just left to right.

itmr

### itmr

Points: 2
fvm - i know that i can comper two ascii value- but i received from the uart 7 ascii code bytes (XXX.XXX) so i need to create the integer packet by its format? am i?
you mean that a good idea is to comper each ascii code byte from the packet?
i thought to convert each byte to integer and to assign it at the suitable place at the packet ? sounds good?

its not as simple as that.

You will have to convert each ascii character to an integer and then sum all the parts. Basically you're doing a string to integer conversion.

itmr

### itmr

Points: 2
trickydicky - you mean that i have to convert each ascii code byte to integer , then multiple each integer by its factor( the first by 100 the second by 10 the third by 1 the fourth by 0.1 and so on..)
and just then sum all the parts?
am i right?? thats what you mean to??

Yes multiply them, and then sum them.

itmr

### itmr

Points: 2
trickydicky - and thats the way i probably convert integers to string?

its not as simple as that.
You will have to convert each ascii character to an integer and then sum all the parts.
Sounds like you wanted to contradict the option to perform decimal arithmetics. The exercise may of course request a (binary) integer conversion, but technically, it's not necessarily needed.

In any case, the ASCII input of numbers to compare must be adjusted according to the decimal point. The initial post is suggesting a fixed decimal format, but the specification may be inexact in this regard.

itmr

### itmr

Points: 2
FVM - i am not sure that i understood you well....what in your opinion the best chice to me? an example to what i mean its:
lets say that i got "35" "36" "37" "point ascii" "38" 30 "31" - then i convert it to 5 6 7 point 8 0 1 then i multiple each value by its factor and get 500 60 7 0.8 0 0.001 , then i sum all the values into integer array(2 downto -3) ?
am i right?

you have to remember that an sfixed is binary - the numbers you are talking about are base 10. You are probably going to need a (9 downto -9) to cover all possible values.

You are probably going to need a (9 downto -9) to cover all possible values.
It's (9 downto -10), 20 bits in total in my opinion. But it's not clear, if you need to convert it to a fractional fixed point format. Alternatively, you can use a decimal scaling factor of 1000 rather 2**10, which simplifies the conversion a lot. And finally, there's the decimal compare option.

You should also specify a data type for the input data, e.g. an array of characters.

floating value means nothing in digital, is always a representation that the designer defined.
then the data tramistted by the UART, on this "strange" format could be transmitted on a more usefull format for a digital mind, isn't it?

Status
Not open for further replies.