FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-23-2008, 11:48 PM
Travis
Guest
 
Posts: n/a
Default Convert a vector to a positive integer?

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!
Reply With Quote
  #2 (permalink)  
Old 11-24-2008, 04:42 AM
testbench
Guest
 
Posts: n/a
Default Re: Convert a vector to a positive integer?

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 <[email protected]> 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!


Reply With Quote
  #3 (permalink)  
Old 11-25-2008, 07:44 PM
Jonathan Bromley
Guest
 
Posts: n/a
Default Re: Convert a vector to a positive integer?

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
[email protected]
http://www.MYCOMPANY.com

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

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert hex string to bit vector in system verilog [email protected]m Verilog 1 10-15-2008 07:07 PM
How Do I Convert an Integer to a String? Chris Verilog 5 03-28-2008 05:25 PM
Integer variable bir Verilog 2 02-01-2007 04:22 PM
Verilog's integer and reg? Davy Verilog 3 03-22-2006 06:48 PM
when to use integer and when to use register Mahurshi Akilla Verilog 2 03-09-2006 09:29 AM


All times are GMT +1. The time now is 12:28 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved