Encode decimal to BaseN string¶
This operation converts a decimal number into a BaseN string. It recursively divides the value by the converter's base to build the digit sequence, then hands the finished digit array to the converter's formatter for final rendering.
| Field | Value |
|---|---|
| Operation ID | OP-BASEN-002 |
| Trigger | Caller request through BaseNConverter.DecimalToBaseN |
| Inputs | Decimal Integer or Long, IConverter |
| Outputs | BaseN string |
| Primary components | BaseNConverter.DecimalToBaseN, BaseNConverter.ConvertDecimalToBaseN, BaseNConverter.ConvertToNumericArray, IConverter.FormatBaseN |
| Entry point | SAIF.Framework.BaseN\BaseNConverter.vb |
Steps¶
- The caller reaches
DecimalToBaseNthrough either itsIntegerorLongoverload. - If the
Integeroverload is used, the value is cast toLongand delegated to theLongoverload; no further conversion logic exists in theIntegerpath. - The
Longoverload calls the recursive helperConvertDecimalToBaseN. - Each recursive frame computes the integer quotient
newValue = value \ converter.Baseand the remainderremainder = value Mod converter.Base. - The frame then builds an intermediate CSV fragment based on the quotient:
- If
newValue >= converter.Base, the frame recurses onnewValuefirst, then appendsconverter.ConvertNumericToAlpha(remainder)to the result returned by the deeper call. - If
newValue = 0, recursion stops and the frame returns onlyconverter.ConvertNumericToAlpha(remainder). - Otherwise, recursion stops and the frame returns
converter.ConvertNumericToAlpha(newValue)followed byconverter.ConvertNumericToAlpha(remainder). - Each of these digit conversions goes through the converter's own
ConvertNumericToAlpha, soHexConverterandExcelConverterenforce their upper-bound checks at this point (BR-001, BR-002). - Once recursion completes, commas are stripped from the CSV result and
ConvertToNumericArrayturns the rendered characters back into a numeric digit array. - That digit array is passed to
converter.FormatBaseN, which renders the final output string. ExcelConverter.FormatBaseNrewrites any zero digit through borrow/rollover logic at this stage, so the result stays in bijectiveA-through-Z,AA-style form (BR-003).- The formatted BaseN string is returned to the caller.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([DecimalToBaseN called]) --> S1{Integer overload?}
S1 -->|Yes| S2[Cast to Long]
S1 -->|No| S3[Enter recursive conversion]
S2 --> S3
S3 --> S4[Compute quotient and remainder]
S4 --> S5[Build intermediate digit CSV]
S5 --> S6[Remove commas and rebuild digit array]
S6 --> S7[FormatBaseN renders final string]
S7 --> EndOk([Return BaseN string])
Failure and edge-case behavior¶
- The
Integeroverload performs only a widening cast toLong; all conversion logic — recursion, digit rendering, and formatting — runs in theLongoverload. HexConverterandExcelConvertercan raiseConverterExceptionmid-recursion if a directIConvertercall supplies a digit value greater than the converter's base while rendering (BR-001, BR-002).ExcelConverterdepends entirely onFormatBaseNto normalize zero digits; without that final formatting pass, the intermediate digit array would still contain literal zeros (BR-003).
Related documentation¶
Sources¶
SAIF.Framework.BaseN\BaseNConverter.vbSAIF.Framework.BaseN\HexConverter.vbSAIF.Framework.BaseN\ExcelConverter.vb