GrayToBinaryConverter constructor

GrayToBinaryConverter(
  1. Logic gray, {
  2. bool reserveName = false,
  3. bool reserveDefinitionName = false,
  4. String? definitionName,
})

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,
    {super.reserveName, super.reserveDefinitionName, String? definitionName})
    : super(
          definitionName:
              definitionName ?? 'GrayToBinaryConverter_W${gray.width}') {
  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),
  ]);
}