AnyBitStream 1.0.20

.NET 5.0 .NET Standard 2.0 .NET Framework 4.6.1
dotnet add package AnyBitStream --version 1.0.20
NuGet\Install-Package AnyBitStream -Version 1.0.20
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="AnyBitStream" Version="1.0.20" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AnyBitStream --version 1.0.20
#r "nuget: AnyBitStream, 1.0.20"
#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.
// Install AnyBitStream as a Cake Addin
#addin nuget:?package=AnyBitStream&version=1.0.20

// Install AnyBitStream as a Cake Tool
#tool nuget:?package=AnyBitStream&version=1.0.20


nuget nuget Build status Codacy Badge

Work with bits efficiently in a stream using standard streams and extending BinaryReader/BinaryWriter.


AnyBitStream is an efficient stream based class for working with data at the bit level. It supports non-standard numeric types such as Int2 to Int7, Int10,Int12,Int24,Int48 and is perfect for working with network protocols or general bit-packing operations.


Install AnyBitStream from the Package Manager Console:

PM> Install-Package AnyBitStream


using AnyBitStream;

var buffer = new byte[64] { // some byte data };
var stream = new BitStream(buffer);
var reader = new BitStreamReader(stream);

// read a 12 byte header
var header = new MyHeader {
  Marker = reader.ReadInt4(),
  ContinuityId = reader.ReadInt3(),
  IsValid = reader.ReadBit(),
  Length = reader.ReadInt32()
// read in some bytes
var data = reader.ReadBytes(header.Length);

Unaligned vs Aligned bytes

By default, the BitStream will not allow unaligned data to be read/written. For example, if you've read 5 bits and then try to read a byte an exception will be thrown. Because you tried to read a byte that doesn't reside on a byte boundary (8 bits) it doesn't want to give you potentially bad data. However sometimes this behavior is desired with certain bit packing formats.

To enable reading/writing unaligned data:

// via constructor(s) on the stream
var stream = new BitStream(true);
var stream = new BitStream(buffer, writable: true, allowUnalignedOperations: true);
// via property
stream.AllowUnalignedOperations = true;
// also available via the reader/writers
var reader = new BitStreamReader(stream, leaveOpen: true, allowUnalignedOperations: true);
var writer = new BitStreamWriter(stream, leaveOpen: true, allowUnalignedOperations: true);

See more on reading unaligned streams in the wiki.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.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
1.0.20 1,566 3/4/2021
1.0.19 284 3/4/2021
1.0.18 251 3/3/2021
1.0.17 237 3/3/2021
1.0.16 229 3/3/2021
1.0.15 265 3/2/2021
1.0.14 250 3/2/2021
1.0.10 237 3/1/2021
1.0.7 239 3/1/2021
1.0.3 229 3/1/2021

Work with bits efficiently in a stream using standard streams and extending BinaryReader/BinaryWriter.