Factorial function with logic.

Discussion in 'Digital Circuit Design' started by Mr.Alan, Jun 10, 2017.

  1. Mr.Alan

    Thread Starter New Member

    Aug 15, 2016
    11
    0
    Hi. I would realy know a way to do factorial function (!) with some kind of circuit with 8-bit data output.
     
  2. Papabravo

    Expert

    Feb 24, 2006
    11,683
    2,455
    This is not very hard. You use a lookup table with a 3-bit input and 8-bit output. All FPGA development tools will synthesize this function. The lookup table produces the following results:

    0! = 1 = 0b0000 0001
    1! = 1 = 0b0000 0001
    2! = 2 = 0b0000 0010
    3! = 6 = 0b0000 0110
    4! = 24 = 0b0001 1000
    5! = 120 =0b0111 1000
    6! = OVERFLOW = any convenient value that is not equal to one of the above outputs
    7! = OVERFLOW = any convenient value that is not equal to one of the above outputs

    And we're done.
     
    Last edited: Jun 10, 2017
    #12 and AnalogKid like this.
  3. #12

    Expert

    Nov 30, 2010
    18,078
    9,617
    That sure beats trying to teach a machine how to multiply!
     
  4. GopherT

    AAC Fanatic!

    Nov 23, 2012
    8,025
    6,785
    You do realize there are only 6 possible output values that Can be possible if you are limited to 8-bit values.
     
Loading...