---
title: Decode BaseN string to decimal
summary: Converts a BaseN character sequence into its decimal `Long` value.
status: draft
owner: SAIF DocGen
last_reviewed: 2026-07-30
library: SAIF.Framework.BaseN
reference_type: package
operation_id: OP-BASEN-001
trigger: Caller invokes `BaseNToDecimal` on a string value.
---

# 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:
   - `BinaryConverter` and `OctalConverter` inherit `ConverterBase`'s default handling, which returns `0` for any character that is not numeric ([BR-004](../business-rules.md#br-004-non-numeric-input-to-the-default-alpha-to-numeric-conversion-is-treated-as-zero)).
   - `HexConverter` returns numeric digits as-is, maps `A`-`F` to `10`-`15`, and raises `ConverterException` for any other value ([BR-001](../business-rules.md#br-001-hexadecimal-digit-must-not-exceed-base-16)).
   - `ExcelConverter` maps one-character alphabetic input through `Asc(input.ToUpper) - 64` and raises `ConverterException` when the mapped value exceeds `26` ([BR-002](../business-rules.md#br-002-excel-base-26-digit-must-not-exceed-base-26)).
4. The completed digit array is passed to `ConvertBaseNToDecimal`.
5. `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.
6. The accumulated total is returned to the caller as the decimal result.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
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](../business-rules.md#br-004-non-numeric-input-to-the-default-alpha-to-numeric-conversion-is-treated-as-zero)).
- `HexConverter` throws `ConverterException` when a token is neither numeric nor `A`-`F`, or when a numeric token exceeds `16` ([BR-001](../business-rules.md#br-001-hexadecimal-digit-must-not-exceed-base-16)).
- `ExcelConverter` throws `ConverterException` when a mapped value exceeds `26` ([BR-002](../business-rules.md#br-002-excel-base-26-digit-must-not-exceed-base-26)).

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## 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`

