Skip to content

BaseNConverter

BaseNConverter is a public VB Module that exposes fluent extension methods for converting between BaseN strings and decimal values against any IConverter implementation, decoupling callers from a converter's internal digit-array plumbing.

Purpose

  • Provide the fluent, extension-method-based public API (BaseNToDecimal, DecimalToBaseN) for this library's base-N conversion functionality.

Context

  • Namespace: SAIF.Framework.BaseN
  • Assembly/package: SAIF.Framework.BaseN (also bundled into the SAIF.BOF.Framework NuGet package)

Public members

Member Signature Purpose
BaseNToDecimal <Extension()> Public Function BaseNToDecimal(ByVal value As String, ByVal converter As IConverter) As Long Extension method on String; converts a BaseN string to its decimal (Long) value using the supplied converter (e.g., "101".BaseNToDecimal(New BinaryConverter()) returns 5).
DecimalToBaseN <Extension()> Public Function DecimalToBaseN(ByVal input As Long, ByVal converter As IConverter) As String Extension method on Long; converts a decimal value to its BaseN string representation using the supplied converter.
DecimalToBaseN (overload) <Extension()> Public Function DecimalToBaseN(ByVal input As Integer, ByVal converter As IConverter) As String Extension method on Integer; overload that delegates to the Long overload via CLng(input).

Behavioral notes

  • BaseNToDecimal converts each character of the input string to a numeric digit via converter.ConvertAlphaToNumeric, then sums digit * Base^position right-to-left (private helpers ConvertToNumericArray, ConvertBaseNToDecimal).
  • DecimalToBaseN recursively divides the input by converter.Base, building a comma-separated alpha digit list via converter.ConvertNumericToAlpha (private helper ConvertDecimalToBaseN), then re-tokenizes it into a digit array and calls converter.FormatBaseN to produce the final string.
  • Private helper methods (ConvertBaseNToDecimal, ConvertDecimalToBaseN, ConvertToNumericArray) are internal implementation details and are not part of the public API.

Constraints and usage notes

  • As VB extension methods, these members require an Imports of the containing namespace (SAIF.Framework.BaseN) and are invoked using instance-method syntax on String/Long/Integer values.
  • Any ConverterException thrown by the supplied converter (e.g., HexConverter, ExcelConverter) propagates to the caller of BaseNToDecimal/DecimalToBaseN uncaught.*

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified. Statements marked with † were retrieved from dependency library documentation via the Legends CLI RAG service. They describe inherited behavior from the indicated origin library and should be verified if the dependency version changes.

Sources

  • SAIF.Framework.BaseN\BaseNConverter.vb