home *** CD-ROM | disk | FTP | other *** search
- PRIME NUMBER RECOGNIZER
-
- Here is an advanced example that defines combinational logic to recognize
- prime numbers. The input A[5..0] represents an integer in the range 0..63
- to be tested for primality. The output P is true if the input integer is
- prime. See the reference guide for an explanation of this example.
-
- | in:A[5..0], io:P
- |
- | Title: "k-bit Prime Number Detection"
- | "Author: TSL"
- |
- | k = 6 |Set the input bit width.
- |
- | n = 2 .. 2**k - 1: |Select the next input value and
- | { j = 0 |clear the number of divisors.
- |
- | n>3: i=2..sqrt(n): |Find how many integers divide the
- | j = j + (n\i==0) |input value evenly.
- |
- | j==0: P = A[k-1..0]==n |If none do, attach a product term
- | } |to the equation.
-
- |Vectors:
- |{ Display (A[5..0])d, P
- | Test A[5..0]
- | End
- | }
-
- Todd S. Lehman, June 1988.
-
-