Fractions

I

Iqbal

Hi all,

I need to do arithmetic using fractions eg. adding +1/4 of an 8 bit
value to another 8 bit value or subtracting
-1/16 of an 8 bit value from another 8 bit value.

Can anyone tell me how I can do this in VHDL or point me in the right
direction ?

Thanks
 
B

Benjamin Todd

Your examples are pretty simple, are you trying to make a generic 'fraction'
or is there only a certain set of values you can accept?

I'd be thinking about 1/(2^n) fractions as an approximation...

Considering that you only have an 8-bit number to start with, this means you
can only go from 0-255... this is probably an exploitable limitation.

Ben
 
T

Thomas Stanka

I need to do arithmetic using fractions eg. adding +1/4 of an 8 bit
value to another 8 bit value or subtracting
-1/16 of an 8 bit value from another 8 bit value.

Can anyone tell me how I can do this in VHDL or point me in the right
direction ?

Z= X + Y/4 for 8 bit unsigned:

Z <= X + "00"&Y(7 downto 2);

bye Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top