GrayToBinaryConverter constructor

GrayToBinaryConverter(
  1. Logic gray
)

Creates a GrayToBinaryConverter instance with the specified Gray code input.

The gray parameter is the Gray code input that you want to convert to binary. The width of the input gray determines the width of the binary output.

Implementation

GrayToBinaryConverter(Logic gray) {
  final inputWidth = gray.width;
  gray = addInput('gray', gray, width: inputWidth);
  final binaryVal = addOutput('binary', width: inputWidth);

  Combinational([
    Case(
        gray,
        [
          for (var i = 0; i < (1 << inputWidth); i++)
            CaseItem(Const(i, width: inputWidth), [
              binaryVal <
                  Const(grayToBinary(LogicValue.ofInt(i, inputWidth)),
                      width: inputWidth),
            ]),
        ],
        conditionalType: ConditionalType.unique),
  ]);
}