Fractions

Discussion in 'VHDL' started by Iqbal, Apr 10, 2007.

  1. Iqbal

    Iqbal Guest

    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
     
    Iqbal, Apr 10, 2007
    #1
    1. Advertising

  2. 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

    "Iqbal" <> wrote in message
    news:...
    > 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
    >
     
    Benjamin Todd, Apr 10, 2007
    #2
    1. Advertising

  3. On 10 Apr., 12:19, "Iqbal" <> wrote:
    > 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
     
    Thomas Stanka, Apr 10, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eoin Mcloughlin

    Decimal places and huge fractions.

    Eoin Mcloughlin, Feb 11, 2004, in forum: Perl
    Replies:
    5
    Views:
    1,637
    Eoin Mcloughlin
    Feb 13, 2004
  2. Lee Jackson

    XSL-FO...Fractions?

    Lee Jackson, Dec 17, 2004, in forum: XML
    Replies:
    3
    Views:
    713
    David Carlisle
    Dec 17, 2004
  3. karp

    Adding two fractions

    karp, Nov 22, 2003, in forum: C++
    Replies:
    2
    Views:
    5,300
    Gary Labowitz
    Nov 22, 2003
  4. =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

    How do I get the fractions of the visible part of a canvas?

    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=, Jul 2, 2003, in forum: Python
    Replies:
    1
    Views:
    330
    Eric Brunel
    Jul 2, 2003
  5. Matthew Wilson

    Need help with list of fractions

    Matthew Wilson, Oct 10, 2003, in forum: Python
    Replies:
    0
    Views:
    296
    Matthew Wilson
    Oct 10, 2003
Loading...

Share This Page