Skip to content

Convert alpha digit to numeric value

This operation maps a single input token to the numeric digit value the active converter expects. The shared base implementation is permissive and never fails; the hex and Excel converters add their own alphabetic mappings and bounds enforcement on top.

Field Value
Operation ID OP-BASEN-004
Trigger Converter digit-decoding request
Inputs String token
Outputs Integer digit value
Primary components ConverterBase.ConvertAlphaToNumeric, HexConverter.ConvertAlphaToNumeric, ExcelConverter.ConvertAlphaToNumeric
Entry point SAIF.Framework.BaseN\ConverterBase.vb

Steps

  1. The input token arrives through IConverter.ConvertAlphaToNumeric.
  2. The call dispatches to whichever converter implementation is active.
  3. ConverterBase checks IsNumeric(input):
  4. If true, it returns CInt(input).
  5. If false, it returns 0 without raising an exception (BR-004).
  6. HexConverter branches on the token's shape:
  7. Numeric input greater than 16 raises ConverterException (BR-001).
  8. Numeric input within range is returned directly.
  9. Non-numeric input is uppercased and mapped from A-F to 10-15.
  10. Any other non-numeric token raises ConverterException (BR-001).
  11. ExcelConverter initializes output = -1 and only attempts conversion when the token is exactly one character long:
  12. A numeric one-character token is returned directly.
  13. An alphabetic one-character token is uppercased and mapped with Asc(input.ToUpper) - 64.
  14. If that mapped value exceeds 26, ConverterException is raised (BR-002).
  15. A token longer than one character bypasses conversion entirely and returns the initialized -1.
  16. The resolved numeric value is returned to the caller.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([ConvertAlphaToNumeric called]) --> D1{Converter type}
    D1 -->|Base/Binary/Octal| S1[Parse numeric or return 0]
    D1 -->|Hex| S2[Parse numeric or map A-F]
    D1 -->|Excel| S3[Require one character and map A-Z]
    S1 --> EndOk([Return integer digit])
    S2 --> D2{Invalid token?}
    D2 -->|Yes| EndErr([Raise ConverterException])
    D2 -->|No| EndOk
    S3 --> D3{Value > 26?}
    D3 -->|Yes| EndErr
    D3 -->|No| EndOk

Failure and edge-case behavior

  • ConverterBase returns 0 for non-numeric input instead of failing; this is the default that BinaryConverter and OctalConverter rely on rather than override (BR-004).
  • HexConverter rejects alphabetic input outside A-F and numeric values greater than 16 (BR-001).
  • ExcelConverter converts only single-character input; multi-character tokens skip the conversion branch entirely and return the initialized -1 sentinel value.
  • ExcelConverter accepts lowercase letters transparently because it normalizes input with ToUpper before mapping.

Sources

  • SAIF.Framework.BaseN\ConverterBase.vb
  • SAIF.Framework.BaseN\BinaryConverter.vb
  • SAIF.Framework.BaseN\OctalConverter.vb
  • SAIF.Framework.BaseN\HexConverter.vb
  • SAIF.Framework.BaseN\ExcelConverter.vb