Skip to content

Decode BaseN string to decimal

This operation reads a BaseN character sequence one character at a time, asks the selected IConverter implementation to resolve each character to a numeric digit, and then sums the digits by positional weight to produce a single decimal value.

Field Value
Operation ID OP-BASEN-001
Trigger Caller request through BaseNConverter.BaseNToDecimal
Inputs Source string, IConverter
Outputs Decimal Long
Primary components BaseNConverter.BaseNToDecimal, BaseNConverter.ConvertToNumericArray, BaseNConverter.ConvertBaseNToDecimal
Entry point SAIF.Framework.BaseN\BaseNConverter.vb

Steps

  1. BaseNConverter.BaseNToDecimal receives the source string and the caller's chosen converter.
  2. ConvertToNumericArray allocates an integer array the same length as the input and walks the source string from left to right, one character at a time.
  3. For each character, converter.ConvertAlphaToNumeric(input.Substring(i, 1)) resolves it to a numeric digit. Behavior differs by converter:
  4. BinaryConverter and OctalConverter inherit ConverterBase's default handling, which returns 0 for any character that is not numeric (BR-004).
  5. HexConverter returns numeric digits as-is, maps A-F to 10-15, and raises ConverterException for any other value (BR-001).
  6. ExcelConverter maps one-character alphabetic input through Asc(input.ToUpper) - 64 and raises ConverterException when the mapped value exceeds 26 (BR-002).
  7. The completed digit array is passed to ConvertBaseNToDecimal.
  8. ConvertBaseNToDecimal walks the digit array from right to left, tracking an increasing power of the converter's base for each position, multiplies each digit by converter.Base ^ power, and adds the result to a running total.
  9. The accumulated total is returned to the caller as the decimal result.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([BaseNToDecimal called]) --> S1[Allocate digit array]
    S1 --> S2[Convert each character to numeric digit]
    S2 --> D{Converter rejects token?}
    D -->|Yes| EndErr([Raise ConverterException])
    D -->|No| S3[Sum digit * Base^position]
    S3 --> EndOk([Return decimal Long])

Failure and edge-case behavior

  • Every source character is forwarded to the converter exactly as it appears in the input; the operation never strips commas, spaces, or other delimiters before conversion, so pre-formatted strings must be normalized by the caller first.
  • BinaryConverter and OctalConverter inherit ConverterBase.ConvertAlphaToNumeric, so any non-numeric character is silently treated as a zero-valued digit rather than rejected (BR-004).
  • HexConverter throws ConverterException when a token is neither numeric nor A-F, or when a numeric token exceeds 16 (BR-001).
  • ExcelConverter throws ConverterException when a mapped value exceeds 26 (BR-002).

Sources

  • SAIF.Framework.BaseN\BaseNConverter.vb
  • 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