Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Conersion of Real number to integer number in VHDL

Status
Not open for further replies.

kaushiksangam

Newbie level 6
Joined
Apr 9, 2006
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,387
vhdl real to integer

I want to convert real numbers to integer numbers in VHDL.

The real numbers that I am using are between -1 and +1. For example I would like to convert the number -0.67857 to a 18 bit signed representation.

Can someone please help me otu with this.
 

real to integer vhdl

First of all, what do you mean with converting real numbers to integers??
Do you mean representing them if floating point?
If what you need is to represent a real number in binary fixed point, then you need first to choose how many bits for the integer part and how many for the fractional part. In the case of range [-1 1], supposing you will use a 2's complement representation, you will need at 2 bits for the integer part, if you use only one bit, than your range will be [-1 0.99...].
If you wish I can send you a Matlab script that converts a floating point value into a fixed point 2's complement value.

If what you need to do is something different please explain what will be your input and output and what is it for.

Regards,
 

convert real number to integer

mendozaulises said:
First of all, what do you mean with converting real numbers to integers??
Do you mean representing them if floating point?
If what you need is to represent a real number in binary fixed point, then you need first to choose how many bits for the integer part and how many for the fractional part. In the case of range [-1 1], supposing you will use a 2's complement representation, you will need at 2 bits for the integer part, if you use only one bit, than your range will be [-1 0.99...].
If you wish I can send you a Matlab script that converts a floating point value into a fixed point 2's complement value.

If what you need to do is something different please explain what will be your input and output and what is it for.

Regards,

I have to implement a Brain State in a Box attractor algorithm in VirtexII pro. I would have to code this in VHDL.

This algorithm involves lot of array multiplications of the numbers from the range[-1 1], but Virtex II pro has a 18*18 bit signed multiplier.

Hence, we have to represent the numbers in that range[-1 1] as an integer, so that we can perform integer multiplication.

Hope, you get my problem.

Thanks
 

vhdl integer to real

I see no bog problem in that. Unless I am again not understanding what you need.
To the multiplier it would be transparent if you use integers or fixed point numbers. To the multiplier it would be just signed integers. It is you who will decide how to represent your numbers. If you will use 18-bit numbers, than I advise you to use format 2.16 for the range [-1 1]. For instance,
A = 11 1000 0000 0000 0000 = -0.5.
Take 2's complement.
A = 00 1000 0000 0000 0000 = 2^-1 +0 +0 +...+0 = 0.5

B=01 0100 0000 0000 0000 = 2^0+2^-2 = 1+0.25 = 1.25.

As you can see, you know that the decimal point is located right after the second bit (from left to right) and still the multiplier will take it as integer.

In the case of multiplication the resulting number is A2.16 * B2.16=C4.32, or if you want to see it like this A18*B18=C36.
If you want your result to be of 18 bits and you are sure it will be in the range [-1 1], and supposing that the left bit is the MSB, you take bits 33 downto 16, and there you will have your C2.16 number.

If you have doubts send me an e-mail to mendozaulises@yahoo.com.

I can also send you an 18-bit multiplier VHDL code.

regards,

Ulises

Added after 32 minutes:

If you don't understand fixed point arithmetic, you can refer to:

h**p://
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top