Skip to content

Repository files navigation

Polecola.Primitive

.NET License: MIT

Polecola.Primitive is a small .NET library for inspecting and manipulating the bit representation of primitive values. It provides extension methods for round-trip conversions between values, byte arrays, and Boolean arrays, plus helpers for reading or changing individual bits and generating character or floating-point ranges.

The library targets .NET Standard 2.1.

Features

  • Convert primitive values to bool[] or byte[] representations.
  • Reconstruct primitive values from Boolean or byte arrays.
  • Read and change individual bits with GetBoolAtIndex and SetBoolAtIndex.
  • Generate end-exclusive ranges for char, float, and double.
  • Use the same extension-method API across signed, unsigned, integral, and floating-point values.

Installation

The project is currently consumed from source. Clone the repository and add a project reference from your application:

git clone https://github.com/MiLattanzio/Polecola.Primitive.git
dotnet add path/to/YourProject.csproj reference path/to/Polecola.Primitive/Polecola.Primitive/Polecola.Primitive.csproj

Then import the namespace:

using Polecola.Primitive;

Quick start

Inspect and change bits

Boolean arrays are least-significant-bit first within each byte, so index 0 represents the least significant bit.

using Polecola.Primitive;

byte value = 0b_0000_0101;

bool[] bits = value.ToBoolArray();
// [true, false, true, false, false, false, false, false]

bool bitTwo = value.GetBoolAtIndex(2);       // true
byte updated = value.SetBoolAtIndex(1, true); // 0b_0000_0111
byte restored = bits.ToByte();                // 0b_0000_0101

Convert values and byte arrays

using Polecola.Primitive;

int original = 42;
byte[] bytes = original.ToByteArray();
int restored = bytes.ToInt();

bool[] representation = original.ToBoolArray();
int fromBits = representation.ToInt();

Generate ranges

Ranges include start and exclude end, like Enumerable.Range.

using Polecola.Primitive;

char[] letters = Polecola.Primitive.Char
    .Range('a', 'f')
    .ToArray(); // a, b, c, d, e

float[] samples = Polecola.Primitive.Float
    .Range(0f, 1f, 0.25f)
    .ToArray(); // 0, 0.25, 0.5, 0.75

double[] descending = Polecola.Primitive.Double
    .Range(1d, 0d, -0.25d)
    .ToArray(); // 1, 0.75, 0.5, 0.25

Always provide an explicit, meaningful step for floating-point ranges. The default is the type's Epsilon, which is usually too small to advance a value at ordinary magnitudes.

Documentation

  • API guide describes the supported conversions, bit ordering, valid indices, range behavior, and portability considerations.
  • XML documentation is emitted with the library assembly.
  • A browsable API site can be generated with Doxygen by running doxygen Doxyfile; output is written to artifacts/docs/html.
  • Contributing guide contains the local build, test, and documentation workflow.

Build and test

The repository requires the .NET 8 SDK or newer:

dotnet restore
dotnet build --no-restore
dotnet test --no-build

License

Polecola.Primitive is available under the MIT License.

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages