NumeralSystems.Net 4.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NumeralSystems.Net --version 4.6.0
                    
NuGet\Install-Package NumeralSystems.Net -Version 4.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NumeralSystems.Net" Version="4.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NumeralSystems.Net" Version="4.6.0" />
                    
Directory.Packages.props
<PackageReference Include="NumeralSystems.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NumeralSystems.Net --version 4.6.0
                    
#r "nuget: NumeralSystems.Net, 4.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NumeralSystems.Net@4.6.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NumeralSystems.Net&version=4.6.0
                    
Install as a Cake Addin
#tool nuget:?package=NumeralSystems.Net&version=4.6.0
                    
Install as a Cake Tool

NumeralSystems.Net

Build License: MIT

English · Italiano

NumeralSystems.Net is a .NET library for representing, converting, and formatting values in arbitrary numeral systems. It also provides bit-oriented primitive wrappers, values with unknown bits, and reverse logical operations.

Use the library when you need to:

  • convert integral or fractional values between bases;
  • format digits with a custom alphabet;
  • inspect and modify the binary representation of primitive values;
  • describe partial values whose bits can be 0, 1, or unknown;
  • recover possible operands of an AND or OR operation.

Requirements

  • .NET 8 SDK to build the solution and run its tests;
  • a .NET Standard 2.1-compatible runtime to consume the library.

The repository contains the library project and its NUnit test suite. A NuGet package is built and published automatically for a valid published GitHub Release, but installing it is not required to try the project.

Quick start

git clone https://github.com/MiLattanzio/NumeralSystems.git
cd NumeralSystems/NumeralSystems.Net
dotnet restore
dotnet build --configuration Release --no-restore
dotnet test --configuration Release --no-build

To consume the source project from another solution:

<ItemGroup>
  <ProjectReference Include="path/to/NumeralSystems.Net.csproj" />
</ItemGroup>

First example

NumeralSystem defines a base. Its indexers create a Numeral from a .NET value.

using NumeralSystems.Net;

var hex = Numeral.System.OfBase(16);

var encoded = hex[255];
Console.WriteLine(encoded);          // FF
Console.WriteLine(encoded.Integer);  // 255

var parsed = hex.Parse("FF");
Console.WriteLine(parsed.Integer);   // 255

Default serialization uses the current culture for its sign and decimal separator. Specify the alphabet and separators explicitly for persistent formats and protocols.

Main APIs

Area Types Purpose
Numeral systems NumeralSystem, Numeral Create, parse, format, and convert values between bases
Non-negative digits Value Store integral digit sequences, including arbitrary-precision integers
Signed and fractional values NumeralValue Convert signed fractions with bounded, observable precision
Bitwise primitives Type.Base.* Wrap bytes, integers, characters, and floating-point values
Unknown bits Type.Incomplete.* Represent ternary bit patterns, enumerate candidates, and test them with Contains
Encoding Type.Base.String, Encoding.String Convert strings to digits in another base and derive symbol identities

Custom alphabet

Each position in identity defines one digit. The alphabet must have at least as many entries as the numeral system's base.

using NumeralSystems.Net;

var dozenal = Numeral.System.OfBase(12);
dozenal.AdjustToFitIntegralLength = false;

var digits = "0123456789XY"
    .Select(character => character.ToString())
    .ToList();

var value = dozenal[143];
var text = value.ToString(digits, separator: "", negativeSign: "-", numberDecimalSeparator: ".");

Console.WriteLine(text); // YY
Console.WriteLine(dozenal.Parse(text, digits, "", "-", ".").Integer); // 143

Reverse bitwise operations

Reverse operations return an incomplete value because multiple operands can produce the same result.

using IntValue = NumeralSystems.Net.Type.Base.Int;

var left = new IntValue { Value = 0b1100 };
var right = new IntValue { Value = 0b1010 };
var result = left.And(right);

if (result.ReverseAnd(right, out var possibleLeft))
{
    Console.WriteLine(result.Value);          // 8
    Console.WriteLine(possibleLeft.Contains(left)); // True
}

Documentation

The complete guide lives in NumeralSystems.Net/docs:

All documentation is maintained as Markdown and versioned with the code. No documentation generator or additional tool is required to read or edit it.

Benchmarks

Performance benchmarks live in a separate project so they do not affect test discovery or execution:

dotnet run --configuration Release \
  --project NumeralSystems.Net.Benchmarks/NumeralSystems.Net.Benchmarks.csproj

Important behavior

  • A positional base must be 2 or greater.
  • Every digit is an integer index in the range 0..base-1.
  • Fractional digits have positional meaning in their declared base; TryToBase reports when a repeating expansion reaches its precision limit.
  • BigInteger indexers and views avoid primitive integer-size limits.
  • Value does not preserve a sign or a fractional part; use NumeralValue or Numeral when those are required.
  • Primitive-wrapper Binary arrays are indexed from the least-significant bit; ToString() provides a human-readable view.
  • Type.Base.String encoding is not Base64 and may produce control characters. Always retain the base and width together with the encoded text.

Contributing and security

Read CONTRIBUTING.md before opening a pull request. Do not report vulnerabilities in public issues; follow SECURITY.md.

The project follows its Code of Conduct and is available under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on NumeralSystems.Net:

Package Downloads
AnyBase.Net

Encode and decode text or bytes with any ordered alphabet.

NumeralSystems.Net.Json

Explicit System.Text.Json integration for exact NumeralSystems.Net values.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.3.0 360 8/1/2026
5.2.0 124 8/1/2026
5.1.0 121 7/31/2026
5.0.0 107 7/31/2026
4.8.1 94 7/31/2026
4.8.0 100 7/31/2026
4.7.0 102 7/31/2026
4.6.0 97 7/31/2026
4.5.2 106 7/30/2026
4.5.1 288 12/8/2024
4.5.0 177 12/8/2024
4.4.0.1 208 12/7/2024 4.4.0.1 is deprecated because it is no longer maintained.
4.4.0 204 12/7/2024 4.4.0 is deprecated because it is no longer maintained.
4.3.0 201 9/10/2024
3.0.0 603 4/18/2022
1.0.1 556 4/2/2022
1.0.0 417 1/7/2022
0.5.0 436 12/19/2021

Adds exact positional fraction conversion with configurable precision and end-to-end BigInteger support.