Convert a vector to a positive integer?

T

Travis

Guest
Hi all -
I've got a statement:
assign shift_out={tempA,tempB}[index]

where tempA and tempB are both 4 bits wide, and I want to pick one
value out of that array that is given by index.
If index comes in as a binary number, how can I convert it to an
integer?

I looked online, there is a $bitstoint(expr) type of things, but that
is for 64 bit input vectors.

I'm using a case statement because I only have 4 options,
but in the future, what is a more elegant solution?

Thanks!
 
Why you want to convert the index manually ?
Verilog does this converison automatically.

Regards,
GopiKrishna
www.testbench.in

On Nov 24, 4:48 am, Travis <TRAy...@gmail.com> wrote:
Hi all -
I've got a statement:
assign shift_out={tempA,tempB}[index]

where tempA and tempB are both 4 bits wide, and I want to pick one
value out of that array that is given by index.
If index comes in as a binary number, how can I convert it to an
integer?

I looked online, there is a $bitstoint(expr) type of things, but that
is for 64 bit input vectors.

I'm using a case statement because I only have 4 options,
 but in the future, what is a more elegant solution?

Thanks!
 
On Sun, 23 Nov 2008 15:48:58 -0800 (PST), Travis wrote:

Hi all -
I've got a statement:
assign shift_out={tempA,tempB}[index]
What makes you think this is legal Verilog?

where tempA and tempB are both 4 bits wide, and I want to pick one
value out of that array that is given by index.
Plenty of other ways to do it:

// assuming shift_out is only 1 bit wide:
assign shift_out = {tempA, tempB} >> index;

// or...
wire [7:0] concat = {tempA, tempB};
assign shift_out = concat[index];

But you cannot (at present) index into an expression;
you can only index a variable or net.
This may change in SV-2009.

If index comes in as a binary number, how can I convert it to an
integer?
As others have said, it's an integer already and
there is nothing you need to do. Just use it.
--
Jonathan Bromley, Consultant

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

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Welcome to EDABoard.com

Sponsor

Back
Top