jason-c-daniels - Jcd.BitManipulation 3.0.105-alpha

A .Net Standard 2.0 library adding syntactic sugar to your bit and byte manipulation experience.

PM> Install-Package Jcd.BitManipulation -Version 3.0.105-alpha -Source https://www.myget.org/F/jason-c-daniels/api/v3/index.json

Copy to clipboard

> nuget.exe install Jcd.BitManipulation -Version 3.0.105-alpha -Source https://www.myget.org/F/jason-c-daniels/api/v3/index.json

Copy to clipboard

> dotnet add package Jcd.BitManipulation --version 3.0.105-alpha --source https://www.myget.org/F/jason-c-daniels/api/v3/index.json

Copy to clipboard
<PackageReference Include="Jcd.BitManipulation" Version="3.0.105-alpha" />
Copy to clipboard
source https://www.myget.org/F/jason-c-daniels/api/v3/index.json

nuget Jcd.BitManipulation  ~> 3.0.105-alpha
Copy to clipboard

> choco install Jcd.BitManipulation --version 3.0.105-alpha --source https://www.myget.org/F/jason-c-daniels/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "jason-c-daniels" -SourceLocation "https://www.myget.org/F/jason-c-daniels/api/v2"
Install-Module -Name "Jcd.BitManipulation" -RequiredVersion "3.0.105-alpha" -Repository "jason-c-daniels" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following symbol server URL: https://www.myget.org/F/jason-c-daniels/api/v2/symbolpackage/


Jcd.BitManipulation

A bit manipulation readability enhancement library.

GitHub MyGet Nuget

Examples

ushort data = 0b0000000000000000;

// turn on all the bits
data = data.SetBits(0, 16); // value is now 0b1111111111111111

// this is the equivalent as above
data = data.SetBits();

// Clear the middle 4 bits.
data = data.ClearBits(4, 8); // value is now 0b1111000000001111

// Toggle all the bits.
data = data.ToggleBits(); // value is now 0b0000111111110000

var finalData = data;
// read the upper byte
var upperByte = (byte) data.ReadBits(8, 8); // upperByte is now 0b00001111

// write 0b1011 into the upper nybble
upperByte = upperByte.StoreBits(0b1011, 4, 4); // upperByte is now 0b10111111

// chaining operations, the same steps and end results
data.ClearBits();
data = data.SetBits(0, 16)  // value is now 0b1111111111111111
           .SetBits()       // this is the equivalent as above
           .ClearBits(4, 8) // value is now 0b1111000000001111
           .ToggleBits();   // value is now 0b0000111111110000

upperByte = ((byte) data.ReadBits(8, 8)) // extract the upper byte (0b00001111)
  .StoreBits(0b1011, 4, 4);              // store the value in the upper 4 bits, now upperByte is now 0b10111111

// finalData 0b0000111111110000
var beByte0     = finalData.ReadByte(0, Endian.Big);              // 00001111
var leByte0     = finalData.ReadByte(0, Endian.Little);           // 11110000

var mutatedData = finalData
                 .StoreByte(0b10111111, 0, Endian.Big)
                 .StoreByte(0b01010101, 0, Endian.Little ); // lower byte is now 0b01010101
;                                                           // mutatedData is now 0b1011111101010101

var beBa = mutatedData.ToByteArray(Endian.Big); // beBa=[0b10111111, 0b01010101]

var leBa = mutatedData.ToByteArray(Endian.Little); // leBa=[0b01010101, 0b10111111]

var leBaToUInt16Le = leBa.ToUInt16(Endian.Little); // leBaToUInt16Le = 0b1011111101010101

var leBaToUInt16Be = leBa.ToUInt16(Endian.Big); // leBaToUInt16Le = 0b0101010110111111

Performance Notes

If you read the code you'll notice a fair number of abstractions and helper structs in use. These don't have a significant impact on release mode performance.

To see how it performs on your system run the code in the Main function of the examples app or run the performance benchmarks using the bash script run-benchmarks. By default it'll try to run .Net Framework 4.6.2 in addition to .Net 8.0. Just edit the script to exclude .Net Framework if your system doesn't have it installed.

The latest performance benchmarks from my machine are available at the links below:

  • BigEndianReadBytes -- Extracts bytes from various integer and floating point types as a big endian array.
  • LittleEndianReadBytes -- Extracts bytes from various integer and floating point types as a little endian array.
  • BigEndianStoreByte -- Stores a single byte in various numeric types at an index using big endian indexing.
  • LittleEndianStoreByte -- Stores a single byte in various numeric type at an index using little endian indexing.
  • BigEndianStoreBytes -- Stores a collection of bytes in various numeric types, indexing into the numeric type's location as if the memory layout were big endian. (i.e. index 0 in the collection is the most significant byte)
  • LittleEndianStoreBytes -- Stores a collection of bytes in various numeric types, indexing into the numeric type's location as if the memory layout were little endian. (i.e. index 0 in the collection is the least significant byte)

Version History

See Release Notes

Dev Notes

  1. v3.1.x-alpha development is now happening in the main branch. A release branch will be created once its ready to be released.

  2. v3.0.x release bug fixes are now happening in the release/3.0 branch.

  3. v2.4.x development has ceased and the branch will be protected.

Build and Status

Build status Quality Gate Status

Statistics

Vulnerabilities Bugs Code Smells Technical Debt

Coverage Lines of Code Duplicated Lines (%)

Ratings

CodeFactor Grade Reliability Rating Security Rating Maintainability Rating

Documentation

Project Website API Docs

  • .NETStandard 2.0
    • Jcd.Netstandard20.Shim (>= 1.0.1)
    • System.Memory (>= 4.5.5)
  • .NETStandard 2.1
    • Jcd.Netstandard20.Shim (>= 1.0.1)
    • System.Memory (>= 4.5.5)
  • .NETStandard 2.0: 2.0.0.0
  • .NETStandard 2.1: 2.1.0.0

Owners

Jason C. Daniels

Authors

Jason C. Daniels

Project URL

https://github.com/jason-c-daniels/Jcd.BitManipulation

License

MIT

Tags

c# csharp bit manipulation

Info

94 total downloads
2 downloads for version 3.0.105-alpha
Download (79.44 KB)
Download symbols (31.13 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
3.1.128 80.93 KB Fri, 13 Sep 2024 01:35:15 GMT 0
3.0.125 80.91 KB Thu, 12 Sep 2024 02:54:20 GMT 2
3.0.124 80.19 KB Thu, 01 Aug 2024 01:36:01 GMT 2
3.0.121 80.2 KB Sun, 14 Apr 2024 18:34:21 GMT 3
3.0.119 80.21 KB Sun, 14 Apr 2024 18:07:49 GMT 0
3.0.118-alpha 80.21 KB Sun, 14 Apr 2024 18:02:15 GMT 0
3.0.115-alpha 80.15 KB Sun, 14 Apr 2024 17:35:04 GMT 1
3.0.112-alpha 80.32 KB Sun, 14 Apr 2024 13:21:57 GMT 0
3.0.108-alpha 80.05 KB Sun, 14 Apr 2024 01:16:23 GMT 3
3.0.105-alpha 79.44 KB Sat, 13 Apr 2024 21:53:32 GMT 2
3.0.102-alpha 78.75 KB Sun, 07 Apr 2024 15:48:41 GMT 3
3.0.99-alpha 78.61 KB Sun, 07 Apr 2024 03:52:55 GMT 1
3.0.96-alpha 78.6 KB Sun, 07 Apr 2024 02:12:11 GMT 0
3.0.90-alpha 77.29 KB Sat, 06 Apr 2024 05:16:03 GMT 3
3.0.87-alpha 67.46 KB Tue, 02 Apr 2024 01:07:13 GMT 3
3.0.55-alpha 66.59 KB Mon, 01 Apr 2024 02:29:52 GMT 3
3.0.32-alpha 66.12 KB Sun, 31 Mar 2024 00:25:30 GMT 6
3.0.30-alpha 73.68 KB Wed, 27 Mar 2024 01:44:16 GMT 2
3.0.27-alpha 73.14 KB Tue, 26 Mar 2024 02:11:14 GMT 1
3.0.23-alpha 72.45 KB Mon, 25 Mar 2024 22:32:37 GMT 1
3.0.19-alpha 47.94 KB Sun, 24 Mar 2024 05:02:16 GMT 1
3.0.16-alpha 45.74 KB Sun, 24 Mar 2024 01:43:23 GMT 0
3.0.14-alpha 49.92 KB Sat, 23 Mar 2024 21:12:15 GMT 2
2.4.33 59.12 KB Sun, 31 Mar 2024 01:25:09 GMT 3
2.4.11 51.66 KB Sat, 23 Mar 2024 19:08:31 GMT 4
2.4.10-pre 51.67 KB Sat, 23 Mar 2024 19:05:39 GMT 1
2.4.8-pre 51.67 KB Sat, 23 Mar 2024 18:59:29 GMT 1
2.4.7-pre 54.61 KB Sat, 23 Mar 2024 18:39:16 GMT 0
2.4.5 54.6 KB Sat, 23 Mar 2024 18:15:41 GMT 1
2.4.0 54.58 KB Sat, 23 Mar 2024 01:07:37 GMT 2
2.3.0 51.78 KB Mon, 18 Mar 2024 23:51:59 GMT 2
2.2.1 51.33 KB Sun, 17 Mar 2024 04:55:26 GMT 1
2.2.0 51.32 KB Sun, 17 Mar 2024 04:22:22 GMT 3
2.1.3 50.31 KB Fri, 15 Mar 2024 00:18:07 GMT 1
2.1.1 49.92 KB Thu, 14 Mar 2024 04:37:00 GMT 2
2.1.0 50.04 KB Thu, 14 Mar 2024 04:07:57 GMT 5
2.0.6 39.38 KB Sat, 20 May 2023 11:01:36 GMT 1
2.0.5 17.73 KB Thu, 23 Mar 2023 02:11:03 GMT 2
1.0.30 139.97 KB Mon, 11 Oct 2021 23:22:12 GMT 2
1.0.28 139.22 KB Mon, 11 Oct 2021 11:57:08 GMT 2
1.0.27 139.24 KB Mon, 11 Oct 2021 11:54:15 GMT 1
1.0.25 139.23 KB Mon, 11 Oct 2021 03:41:27 GMT 1
1.0.24 139.24 KB Mon, 11 Oct 2021 03:22:48 GMT 0
1.0.23 139.23 KB Sun, 10 Oct 2021 02:38:55 GMT 1
1.0.22 139.67 KB Sun, 10 Oct 2021 01:53:49 GMT 0
1.0.21 139.63 KB Sun, 10 Oct 2021 01:47:17 GMT 0
1.0.19 139.66 KB Sun, 10 Oct 2021 01:40:35 GMT 2
1.0.17 139.68 KB Sun, 10 Oct 2021 00:28:04 GMT 1
1.0.15 139.67 KB Sun, 10 Oct 2021 00:12:50 GMT 0
1.0.14 139.67 KB Sat, 09 Oct 2021 23:59:35 GMT 1
1.0.13 139.67 KB Sat, 09 Oct 2021 23:39:06 GMT 1
1.0.11 139.65 KB Sat, 09 Oct 2021 20:50:23 GMT 0
1.0.10 140.17 KB Sat, 09 Oct 2021 20:43:07 GMT 1
1.0.9 137.1 KB Sat, 09 Oct 2021 20:14:30 GMT 0
1.0.8 94.8 KB Sat, 09 Oct 2021 05:36:25 GMT 10
1.0.7 94.83 KB Sat, 09 Oct 2021 05:23:06 GMT 0
1.0.6 94.83 KB Sat, 09 Oct 2021 04:51:04 GMT 1
1.0.3 93.84 KB Sat, 09 Oct 2021 00:28:38 GMT 1
1.0.2 11.14 KB Thu, 07 Oct 2021 04:02:19 GMT 1
1.0.1 6.47 KB Wed, 06 Oct 2021 03:32:37 GMT 0