BinaryToGrayConverter constructor
- Logic binary
Creates a BinaryToGrayConverter instance with the specified binary input.
The binary
parameter is the binary input that you want to convert
to Gray code. The width of the input binary
determines the width
of the Gray code output.
Implementation
BinaryToGrayConverter(Logic binary) {
final inputWidth = binary.width;
binary = addInput('binary', binary, width: inputWidth);
final grayVal = addOutput('gray', width: inputWidth);
Combinational([
Case(
binary,
[
for (var i = 0; i < (1 << inputWidth); i++)
CaseItem(Const(i, width: inputWidth), [
grayVal <
Const(binaryToGray(LogicValue.ofInt(i, inputWidth)),
width: inputWidth)
])
],
conditionalType: ConditionalType.unique)
]);
}