Tree3.Converter 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tree3.Converter --version 1.0.2
                    
NuGet\Install-Package Tree3.Converter -Version 1.0.2
                    
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="Tree3.Converter" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tree3.Converter" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Tree3.Converter" />
                    
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 Tree3.Converter --version 1.0.2
                    
#r "nuget: Tree3.Converter, 1.0.2"
                    
#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 Tree3.Converter@1.0.2
                    
#: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=Tree3.Converter&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Tree3.Converter&version=1.0.2
                    
Install as a Cake Tool

tree3-calc-converter


## tree3-calc-converter

tree3-calc-converter converts a decimal number provided as a string into its binary representation (and vice versa). 
It is implemented to handle arbitrarily large integers using `System.Numerics.BigInteger` and runs the conversion asynchronously.

### Prerequisites
- C# 13.0
- .NET 9

### Public API
- Class DecimalToBinary, `Task<string> RunAsync(string numberAsString)`
- Class BinaryToDecimal, `Task<string> RunAsync(string numberAsString)`

Behavior:
- Returns the binary string representation of the input decimal number on success.
- Returns `"N/A"` when the input is invalid or cannot be parsed as a decimal integer.
- Trims leading zeros before parsing.
- Handles large integers via `BigInteger`.
- Zero input returns `"0"`.

### Usage

Example C# usage:
```csharp
// Example 1: Valid decimal string
string binary = await converter.RunAsync("42");
// binary is "101010"

// Example 2: Decimal string with leading zeros
string binaryWithLeadingZeros = await converter.RunAsync("00042");
// binaryWithLeadingZeros is "101010"

// Example 3: Zero input
string zeroBinary = await converter.RunAsync("0");
// zeroBinary is "0"

// Example 4: Invalid input
string invalidBinary = await converter.RunAsync("abc");
// invalidBinary is "N/A"

// Example 5: Empty input
string emptyBinary = await converter.RunAsync("");
// emptyBinary is "N/A" (depends on BaseConverter.Validate)

// Example 6: Very large integer string
string largeBinary = await converter.RunAsync("12345678901234567890");
// largeBinary is the binary representation of the large number
```

### Examples and Expected Results

- Input: `"42"` -> Output: `"101010"`
- Input: `"00042"` -> Output: `"101010"`
- Input: `"0"` -> Output: `"0"`
- Input: `"abc"` -> Output: `"N/A"`
- Input: `""` (empty) -> Output: `"N/A"` (depends on `BaseConverter.Validate`)
- Input: very large integer string -> Output: large binary string (conversion uses `BigInteger` and may be CPU intensive for huge inputs)

### Implementation Notes

- Parsing is performed with `BigInteger.Parse`. If parsing fails, the method returns `"N/A"`.
- Conversion to binary uses bitwise operations and constructs the binary string efficiently with a `StringBuilder`.
- The heavy work is executed on a thread-pool thread via `Task.Run` so callers do not block on long conversions.
- The class relies on `BaseConverter.Validate` to determine initial validity and `BaseConverter.RemoveLeadingZeros` to normalize inputs.

### Troubleshooting

- If very large numbers cause high CPU or memory usage, consider imposing a length limit before parsing or using streaming/segment conversion if applicable.
- If `Validate` behavior is unexpected, inspect the `BaseConverter` implementation.
- Non-integer decimal strings (e.g., with decimal point or sign) will depend on `Validate` and `BigInteger.Parse` behavior; currently, parsing expects an integer format.
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Tree3.Converter:

Package Downloads
Tree3.Calculator

Performs addition, subtraction, multiplication, division, and modulo operations on arbitrarily large non-negative integers represented as strings.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 367 11/30/2025
2.0.0 189 11/15/2025
1.1.0 227 11/5/2025
1.0.2 212 11/4/2025
1.0.1 215 11/3/2025
1.0.0 205 11/3/2025