The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Mar 29th, 2024, 6:24am
Pages: 1
Send Topic Print
Access bits of integer (Read 1633 times)
Gornarok
New Member
*
Offline



Posts: 1

Access bits of integer
Dec 11th, 2016, 9:44am
 
Hello,
Id like to make a modul that has integer as input and outputs its value as bits. Is it possible to access bits of integer? Or can I converse integer to bit vector? What would the best way to do it?

I wanted to do something like this:

Code:
analog begin

	generate i (fN-1,0)begin
		V(filter_out[i]) <+ filter_in[i] ? V(vdd): V(vssr);
	end

	generate i (gN-1,0) begin
		V(gain_out[i]) <+ gain_in[i] ? V(vdd): V(vssr);
	end
end
 

Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Access bits of integer
Reply #1 - Dec 13th, 2016, 5:38pm
 
The easiest way to do this is to do a bit-wise and. So something like:
Code:
generate i (gN-1,0)
    V(gain_out[i]) <+ transition(gain_in & (1 << i) ? 1 : 0, 0, 1u) * (V(vdd) - V(vssr)) + V(vssr); 


Use of the transition function is also important.

Use of genvars is now preferred over use of the generate statement, so you should probably use:
Code:
genvar i;
for (i = 0; i < gN; i = i+1)
    V(gain_out[i]) <+ transition(gain_in & (1 << i) ? 1 : 0, 0, 1u) * (V(vdd) - V(vssr)) + V(vssr); 



-Ken
Back to top
 
 
View Profile WWW   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.