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¶
BaseNConverter.BaseNToDecimalreceives the source string and the caller's chosen converter.ConvertToNumericArrayallocates an integer array the same length as the input and walks the source string from left to right, one character at a time.- For each character,
converter.ConvertAlphaToNumeric(input.Substring(i, 1))resolves it to a numeric digit. Behavior differs by converter: BinaryConverterandOctalConverterinheritConverterBase's default handling, which returns0for any character that is not numeric (BR-004).HexConverterreturns numeric digits as-is, mapsA-Fto10-15, and raisesConverterExceptionfor any other value (BR-001).ExcelConvertermaps one-character alphabetic input throughAsc(input.ToUpper) - 64and raisesConverterExceptionwhen the mapped value exceeds26(BR-002).- The completed digit array is passed to
ConvertBaseNToDecimal. ConvertBaseNToDecimalwalks the digit array from right to left, tracking an increasing power of the converter's base for each position, multiplies each digit byconverter.Base ^ power, and adds the result to a running total.- 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.
BinaryConverterandOctalConverterinheritConverterBase.ConvertAlphaToNumeric, so any non-numeric character is silently treated as a zero-valued digit rather than rejected (BR-004).HexConverterthrowsConverterExceptionwhen a token is neither numeric norA-F, or when a numeric token exceeds16(BR-001).ExcelConverterthrowsConverterExceptionwhen a mapped value exceeds26(BR-002).
Related documentation¶
Sources¶
SAIF.Framework.BaseN\BaseNConverter.vbSAIF.Framework.BaseN\ConverterBase.vbSAIF.Framework.BaseN\BinaryConverter.vbSAIF.Framework.BaseN\OctalConverter.vbSAIF.Framework.BaseN\HexConverter.vbSAIF.Framework.BaseN\ExcelConverter.vb