Factorial function with logic.

Thread Starter

Mr.Alan

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

Papabravo

Joined Feb 24, 2006
21,227
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:
Top