NumeralSystems.Net
4.5.2
See the version list below for details.
dotnet add package NumeralSystems.Net --version 4.5.2
NuGet\Install-Package NumeralSystems.Net -Version 4.5.2
<PackageReference Include="NumeralSystems.Net" Version="4.5.2" />
<PackageVersion Include="NumeralSystems.Net" Version="4.5.2" />
<PackageReference Include="NumeralSystems.Net" />
paket add NumeralSystems.Net --version 4.5.2
#r "nuget: NumeralSystems.Net, 4.5.2"
#:package NumeralSystems.Net@4.5.2
#addin nuget:?package=NumeralSystems.Net&version=4.5.2
#tool nuget:?package=NumeralSystems.Net&version=4.5.2
NumeralSystems.Net
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
ANDorORoperation.
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 and convert their base |
| Signed and fractional values | NumeralValue |
Store integral/fractional parts and convert to or from .NET values |
| 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:
- getting started and integration;
- numeral systems and alphabets;
- primitive wrappers and bitwise operations;
- incomplete values and reverse operations;
- string encoding;
- API reference;
- release and NuGet publishing process.
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. Valuedoes not preserve a sign or a fractional part; useNumeralValueorNumeralwhen those are required.- Primitive-wrapper
Binaryarrays are indexed from the least-significant bit;ToString()provides a human-readable view. Type.Base.Stringencoding 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 | Versions 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. |
-
.NETStandard 2.1
- Polecola.Primitive (>= 1.0.0)
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 | 204 | 12/7/2024 | |
| 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 |
Improves validation, build quality, deterministic testing, and package metadata.