JBlam.Collections.ValueBitArray 0.0.1-testing

This is a prerelease version of JBlam.Collections.ValueBitArray.
dotnet add package JBlam.Collections.ValueBitArray --version 0.0.1-testing
                    
NuGet\Install-Package JBlam.Collections.ValueBitArray -Version 0.0.1-testing
                    
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="JBlam.Collections.ValueBitArray" Version="0.0.1-testing" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JBlam.Collections.ValueBitArray" Version="0.0.1-testing" />
                    
Directory.Packages.props
<PackageReference Include="JBlam.Collections.ValueBitArray" />
                    
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 JBlam.Collections.ValueBitArray --version 0.0.1-testing
                    
#r "nuget: JBlam.Collections.ValueBitArray, 0.0.1-testing"
                    
#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 JBlam.Collections.ValueBitArray@0.0.1-testing
                    
#: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=JBlam.Collections.ValueBitArray&version=0.0.1-testing&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=JBlam.Collections.ValueBitArray&version=0.0.1-testing&prerelease
                    
Install as a Cake Tool

JBlam.Collections.ValueBitArray

A thin value-type wrapper around an underlying integer value.

Designed to help represent heavily compacted low level datastructures you might find in microcontroller register values.

Usage

using JBlam.Collections.Immutable;

const byte B = 0b0101_0011;

// The backing type is generic. Use ushort, uint, ulong, BigInteger, etc.
var bitarray = ValueBitArray.Create(B);
bool isBit1Set = bitarray[1];
byte highNibble = bitarray.GetShifted(4..); // equals 0b0101

// you can also: enumerate each bit, enumerate the set indicies, work with unshifted masks,
// test equality, perform bitwise AND / OR / XOR / NOT, etc.

Not a re-implementation of BCL's BitArray or BitVector32

System.Collections.BitArray is a quite different design to this:

  • The BCL BitArray type is a class, with a variable-length backing memory array of bytes. This type is a value type, and has a fixed size if the underlying T has a fixed size. (Most integer types are fixed-size, but BigInteger is not.)
  • The BCL BitVector32 type is fixed to 32-bit integers. The JBlam type is generic, so it can be type-safe over your target integer size. (For example, you might be interacting with a microcontroller which uses a 16-bit integer registry.)
  • The BCL BitVector32 type has a complex Section construct for subranges. The JBlam type indexes bits directly, and allows subrange access by index using Range.

Not the same as [Flags] enum

There is some functional overlap between ValueBitArray<T> and a flags enum. For example:

using JBlam.Collections.Immutable;

[Flags]
enum E
{
    None = 0,
    Sharks = 0b0001,
    Kittens = 0b0010,
    Asparagus = 0b01000,
}

var e = (E)(0b1010);
var enumHasKittens = e.HasFlag(E.Kittens);

const int KittensBit = 0b0010;
var bitarray = new ValueBitArray<byte>(0b1010);
var bitarrayHasKittens = bittarray[KittensBit];

My suggestion for how to choose:

  • If you are interacting with 10 or more different bit patterns, use ValueBitArray. Supporting that many enum types is too hard.
  • If there are logically "embedded integers" inside bitmasks, use ValueBitArray.
  • If you need to flexibly support new bitmask layouts without recompiling your program, use ValueBitArray. Flags enums must be defined at compile time (or using Reflection, or ILEmit).
  • Otherwise, use Flags enums. The declaration is somewhat nicer, and strong-typing the members is useful.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1-testing 63 2/11/2026

0.0.1; Initial release