Continue to Site

# (help)floating point to binary in verilog

Status
Not open for further replies.

#### rajsrikanth

##### Full Member level 2
how to convert floating point into binary verilog

can any one help me to develop code to convert a floating point number to binary and writing code in verilog.
can u sujjest some sites or material or can give any code for that
pls help. i have to develop a FIr filter in verilog and in that i have a need to convert floating point filter coeffecients to binary and hv to develop coding in verilog.
and i have to implement in FPGA.

thanx and regards
raj

floating point in verilog

matlab is the best.
try FDATool in Matlab.
u can design a FIR filter quantize it to fixed point generate verilog/VHDL code and do a cosimulation in an FPGA.
Regards

### rajsrikanth

Points: 2
verilog floating point to integer

i faced this problem before, finally, i wrote a matlab script to do it:
Code:
        function bin_str=decim2bin(decimal,decbits);

% check parameter
if nargin==0, error('usage: decim2bin(decimal, decimalbits)'); end
if nargin==1, decbits=32; end

% check wether is a neg number
is_neg=0;

int=fix(decimal);

if decimal <0
is_neg=1;
dec=int-decimal;
int=-int;
bin_str='1';
else
dec=decimal-int;
bin_str='0';
end

int_str=dec2bin(norm(int));

if is_neg
int_str=char('0'+'1'-int_str);
if dec==0
int_bits=(length(int_str));
int=power(2,int_bits)-int;
int_str=dec2bin(int);
int_len=length(int_str);
if int_bits>int_len
int_fill_str=blanks(int_bits-int_len);
int_fill_str(:)='0';
int_str=[int_fill_str int_str];
end
end
end

bin_str=[bin_str int_str ];

if dec~= 0
bin_str=[bin_str '.'];
int_bits=length(int_str);

if is_neg
dec=1-dec;
end

dec_str=blanks(decbits);
dec_str(:)='0';
bin_str=[bin_str  dec_str];

for n=1:decbits
dec=dec*2;
if dec >=1
bin_str(n+int_bits+2) = '1';
dec=dec-1;
end
end

end

### rajsrikanth

Points: 2
decimals loating point verilog

I usually multiply all the floating point values by a constant, round them off to integers, and enter those integers into my HDL.

Status
Not open for further replies.