Expand description
Mathematical base representation, positional numeral systems, and number string conversion utilities.
This module addresses two distinct, interrelated domains:
-
Mathematical Positional Radix Systems (Number-Oriented):
- Represents numeric quantities in positional notation across integer
radices from 1 (unary) to 64 (
Base,BaseAlphabet,NumeralSystem). - Evaluates and formats scalar mathematical values (
Natural, integer primitives). - In positional number systems, leading zeros are semantically inert in
value (e.g.
0042and42denote the identical scalar integer).
- Represents numeric quantities in positional notation across integer
radices from 1 (unary) to 64 (
-
Delimited Text Stream Parsing & Formatting (String-Oriented):
- Parses, converts, and formats strings containing one or more numbers
separated by delimiters (commas, spaces) or prefixes (
0x,0b,0o) viaformat_base_stringandbase_to_base_string. - Configured via
BaseStringFormatSettings, supporting custom padding, delimiters, character filtering, and radix prefixes. - Supports fixed-width digit chunking via the
limitconfiguration parameter (e.g.limit = 255allows chunking numbers into byte-sized units).
- Parses, converts, and formats strings containing one or more numbers
separated by delimiters (commas, spaces) or prefixes (
§Distinction from Byte-Stream Data Armoring
This module is intended for mathematical numerals, not for arbitrary binary byte data armoring:
- In data armoring (e.g. continuous hex streams, hexdumps, Base16b, or
RFC 4648 Base64 byte armoring), exact byte framing is critical: leading
0x00bytes are real data elements whose removal alters data length and corrupts serialization. - In positional numerals (this module), values are abstract scalars.
While
BaseAlphabet::Base64Standardis provided, it represents a mathematical base-64 positional radix ($b = 64$) overNaturalnumbers, rather than an octet-stream block armor codec. - For raw byte sequence armoring and hexdumps, refer to
ctb_formats_armor,ctb_formats_hexdump, andctb_formats_base64.
Structs§
- Base
- Represents a mathematical integer base / radix (e.g. 1, 2, 8, 10, 16, 64).
- Base
Conversion Padding Mode - Zero-padding configuration for delimited base string conversion.
- Base
String Format Settings - Settings for parsing and formatting delimited strings of numbers across bases.
- Numeral
System - Represents a numeral system defined by a mathematical radix and a digit alphabet.
Enums§
- Base
Alphabet - Alphabet used by a numeral system.
Constants§
Functions§
- base_
to_ base_ string - Parse a string containing numbers in base 2 through 64, convert it to the target base, and print it formatted. Will warn for extra characters other than spaces and commas.
- casefold_
base_ chars_ in_ string - char_
to_ digit - Parses a single character into a digit value in the given base.
- dec_
to_ hex_ single - dec_
to_ hex_ string - Convenience function to convert a delimited string of decimal numbers to hexadecimal using default format settings.
- digit_
to_ char - Returns the single-character digit for a numeric value in the given base.
- format_
base_ string - Parse a string containing numbers in base 2 through 64 and print it formatted. Will warn for extra characters other than spaces and commas.
- format_
natural - Formats a
Naturalnumber in the given base with optional minimum width. - format_
natural_ system - Formats a
Naturalnumber in the given numeral system with optional minimum width. - get_
digits_ needed - hex_
to_ dec_ single - hex_
to_ dec_ string - Convenience function to convert a delimited string of hexadecimal numbers to decimal using default format settings.
- int_
from_ base_ str_ big - Returns the integer represented by n in the requested base.
- int_
from_ base_ str_ big_ alphabet - Returns the integer represented by n in the requested base using the given alphabet.
- int_
from_ base_ str_ u32 - Returns the integer represented by n in the requested base.
- int_
from_ base_ str_ u128 - Returns the integer represented by n in the requested base.
- int_
to_ base_ str - Returns the integer represented by n in the requested base.
- int_
to_ base_ str_ big_ alphabet - Returns the string representation of an arbitrary-precision integer in the requested base and alphabet.
- is_
base_ digit - Returns true if the single-character string is a valid digit in the standard alphabet for the given base.
- is_
base_ digit_ alphabet - Returns true if the character is a valid digit for the given base in the specified alphabet.
- is_
base_ str - Returns true if all characters in the string are valid digits in the standard alphabet for the given base.
- is_
base_ str_ alphabet - Returns true if all characters in the string are valid digits for the given base in the specified alphabet.
- is_
supported_ base - Returns true if the numeric base is supported (1..=64).
Radices greater than 36 require an expanded alphabet such as
BaseAlphabet::Base64Standard. - is_
supported_ base_ with_ default_ alphabet - Returns true if the base is supported by the standard alphanumeric alphabet (1..=36).
- parse_
natural - Parses a string representing a number in the given base into a
Natural. - parse_
natural_ system - Parses a string representing a number in the given numeral system into a
Natural.