Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling bit_vectors/integers

Status
Not open for further replies.

blues82

Programmer
Apr 29, 2004
1
US
I am working on a project in which I am taking to inputs..say 2 and 4. From these I need to create 24. Like using a tv remote control. Any suggestions at all would be appreciated. This is the final piece of my puzzle and an urgent fix is needed.
 
well it depends... if you are talking hex then its easy.
but I am guessing you want decimal... not so easy.

I will assume that the inputs can only be 0-9. You result could therefore by 0 - 99 which means we need 7 bits.

So, now you need res = num1*10 + num2

multiplying by 10 may not be an option, so instead lets change it to

res = num1*8 + num1*2 + num2.

so declare a signal called num1x8 and num1x2.
num1 and num2 will be 4 bits each. so num1x8 will be 7 bits and num1x2 will be 5 bits
num1x2 <= num1 & '0';
num1x8 <= num1 & "000";

so now res <= num1x8 + num1x2 + num2;

we know that the result will be less than 99, but the synthesizer won't know that. It will probably complain if you make res a 7 bit number.

so you can either make res 8 bits and only use the lowest 7 bits, or you can say
res <= (num1x8 + num1x2 + num2)(6 downto 0);

I think that should work.

Anyway, you should be able to get their from what I have told you.

--
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top