I'm trying to make a 7 to 3 priority encoder for a circuit diagram for a class. The problem is that we have to take in a 7 bit number and output a 3 bit answer representing the maximum number of consecutive ones in the input.

Example:

```
0011100 = 011 (3)
1111111 = 111 (7)
0000000 = 000 (0)
```

The issue at the moment is that regardless of the input, it is always outputting 111 (7).

I have circuits for handling every possible combination of consecutive ones in the input, and am then piping that into a 7 to 3 priority encoder, but for some reason the encoder is not working the way it should. What am I doing wrong? Or is there a better way that I should be doing this?

Original Circuit diagram:

Attempt 2:

## Best Answer

`PE2`

and`PE3`

outputs?`1111111`

,`PE1..PE7`

are all going to be`1`

, so the last diagram would be wrong.`NAND`

is a much easier function to play with for consecutive`1`

s.here's how I would do it: