integer to binary conversion

Jan 05, 2008 3 Replies

I am converting an integer to a single precision floating point number.



I understand that floating point number comprises of sign bit(1 bit), exponent(8 bits) and significand(23 bits).



I can check if input < 0 and get the sign bit.



To get the exponent and mantissa, I have to convert the integer to binary.



I am using the function "to_unsigned" in VHDL.



The problem is since i dont know how big of an integer i can get as input, I dont know how i should declare the length of the binary vector . The integer to binary conversion could give me anywhere from a minumum of 1 bits to a maximum of (I dont know).



I would like to know how to solve this problem


The largest integer in the VHDL language is "integer'high" (the smallest is "integer'low" if you're curious). Run the code below in a simulator and it will print out what that value is. Presumably you can then figure out how many bits it will take to represent this number

entity Foo is end Foo; architecture RTL of Foo is begin assert FALSE report "The largest integer is..." & integer'image(integer'high) severity NOTE; end RTL;

KJ

s

it

ow

high)

Thanks a lot for your help. I figured the largest integer to be

2147483647 and smallest would be -2147483647 . It takes 31 bits to accomodate the smallest number and 64 bits to accomodate the largest number.

There is one more question I have. If i am converting a signed bit string(of unknown length) to a Single precision floating point number, would the floating point number be represented as a signed bit stirng or unsigned.

Thanks

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required