real number to 16 bit signed number

H

hari

Guest
hi
a) i want to convert a real number to 16 bit signed binary number.
the real number is 2E15-1.so how should i do it.do we have any
default packages for that.

thanks
hari
 
"hari" <hari_pro@yahoo.com> wrote in message
news:a4a587f1.0404272014.340b51d0@posting.google.com...
hi
a) i want to convert a real number to 16 bit signed binary number.
the real number is 2E15-1.so how should i do it.do we have any
default packages for that.
Assuming you mean SIGNED from Numeric_std, you could use

library IEEE;
use IEEE.NUMERIC_STD.all;

....

signal S : SIGNED(15 downto 0)
signal V : STD_LOGIC_VECTOR(15 downto 0);
signal I : INTEGER range -2**15 to 2**15-1;
signal R : real;

....

S <= to_signed(INTEGER(R),16));

If you want to go to std_logic_vector, then

V <= STD_LOGIC_VECTOR(to_signed(INTEGER(R),16)));

If you meant just an integer, then they are closely related so you can
just
do

I <= INTEGER(R);


The conversion rounds.

regards

Alan

--
Alan Fitch
Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project
Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
1AW, UK
Tel: +44 (0)1425 471223 mail:
alan.fitch@doulos.com
Fax: +44 (0)1425 471573 Web:
http://www.doulos.com

The contents of this message may contain personal views which are not
the
views of Doulos Ltd., unless specifically stated.
 
"hari" <hari_pro@yahoo.com> escribió en el mensaje
news:a4a587f1.0404272014.340b51d0@posting.google.com...
hi
a) i want to convert a real number to 16 bit signed binary number.
the real number is 2E15-1.so how should i do it.do we have any
default packages for that.

thanks
hari
i guess you meant 2 "to the power of" 15 minus 1 = 32768-1 am i right? if
so, then it's an integer and therefore it's trivial to convert it, but then,
the whole thing seem too trivial
 
sorry the real number is 0.9990234375 and i want to convert it to a 16
bit binary number .can u guys help me out.
thanks
hari
 
Is standard C code OK ???

hari wrote:
sorry the real number is 0.9990234375 and i want to convert it to a 16
bit binary number .can u guys help me out.
thanks
hari
 
i have to do it in vhdl.but yes the c code should be ok.i can try
converting it to vhdl.
thanks
hariprasath
 
OK,

float sample;
int answer;

answer = int( sample );


simplified would be:

if( sample < 1.0000 )
answer = 0;



Did I miss something or did you not give enough information ??


hari wrote:

i have to do it in vhdl.but yes the c code should be ok.i can try
converting it to vhdl.
thanks
hariprasath
 

Welcome to EDABoard.com

Sponsor

Back
Top