bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to convert Bit#(n) to Integer?

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
roMoon



Joined: 26 Jul 2009
Posts: 8

PostPosted: Mon May 31, 2010 11:41 pm    Post subject: how to convert Bit#(n) to Integer? Reply with quote

I want to convert Bit#(4) to Integer, and I didn't find any off-the-shelf function to use. I have tried to use pack and unpack but failed. Do I have to write a function myself to perform the convert ?
Back to top
View user's profile Send private message
jnewbern



Joined: 18 Jul 2007
Posts: 71

PostPosted: Wed Jun 02, 2010 9:32 am    Post subject: Reply with quote

First, it is important to distinguish between compile-time values and synthesized values. Compile-time values are used during the compilation process but do not appear in the generated circuit.

The Integer type is available only at compile-time, whereas Bit, UInt, etc. can be synthesized as well as used at compile-time. This distinction is why there are functions to convert from Integer to Bit, UInt, etc. but not vice-versa.

If your Bit#(4) value is not a compile-time value, then it cannot be converted to an Integer. If your Bit#(4) value is a compile-time value, then this usually indicates that it has been converted to a Bit value prematurely. You should perform the calculation using Integers and then convert to a Bit#(4) only at the point that you need to move the value from compile-time to synthesis.

I hope this was helpful. If not, a little more information about the specific issue and your need to convert from Bit#(4) to Integer might elicit more detailed suggestions.

Jeff
Back to top
View user's profile Send private message
roMoon



Joined: 26 Jul 2009
Posts: 8

PostPosted: Mon Nov 15, 2010 10:33 am    Post subject: Reply with quote

thank you, jnewbern.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP