Thermometer Code Detector
Medium · Combinational · SystemVerilog
Thermometer (a.k.a. unary) coding is frequently used in digital systems applications to represent a natural number. In a thermometer code, a binary number is represented by a $2^N$-bit digital word with value $m$, which has $m$ zeros followed by $(N - m)$ ones or vice-versa.
Implement a thermometer code detector. The module has two ports, {codeIn} and {isThermemeter}. The former is a binary word, and the latter is the signal that indicates whether or not the input is a thermometer code. The module must support both types of thermometer representations. For instance, the detector must detect thermometer representations that use $m$ zeros followed by $(N - m)$ ones or $m$ ones followed by $(N - m)$ zeros.