{"id":20783742,"url":"https://github.com/menaver/menaver.netbitset","last_synced_at":"2026-05-20T10:02:08.222Z","repository":{"id":239917181,"uuid":"786931237","full_name":"Menaver/Menaver.NetBitSet","owner":"Menaver","description":"Inspired by std::bitset from C++, NetBitSet represents a .NET implementation of an operable sequence of bits.","archived":false,"fork":false,"pushed_at":"2025-02-10T11:13:27.000Z","size":175,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-07T01:57:06.006Z","etag":null,"topics":["bit","bitset","dotnet","encryption"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/Menaver.NetBitSet","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Menaver.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-15T15:16:24.000Z","updated_at":"2024-12-26T16:18:40.000Z","dependencies_parsed_at":"2024-07-17T22:32:17.877Z","dependency_job_id":"b25d685d-273f-429a-9b5b-114cf2fcefbe","html_url":"https://github.com/Menaver/Menaver.NetBitSet","commit_stats":null,"previous_names":["menaver/menaver.netbitset"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Menaver/Menaver.NetBitSet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menaver%2FMenaver.NetBitSet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menaver%2FMenaver.NetBitSet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menaver%2FMenaver.NetBitSet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menaver%2FMenaver.NetBitSet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Menaver","download_url":"https://codeload.github.com/Menaver/Menaver.NetBitSet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menaver%2FMenaver.NetBitSet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265088864,"owners_count":23709597,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bit","bitset","dotnet","encryption"],"created_at":"2024-11-17T14:23:01.263Z","updated_at":"2026-05-20T10:02:08.147Z","avatar_url":"https://github.com/Menaver.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview \u003ca name=\"overview\"\u003e\u003c/a\u003e\n\nInspired by [std::bitset](https://en.cppreference.com/w/cpp/utility/bitset) from C++, `NetBitSet` represents a .NET implementation of an operable sequence of bits. `NetBitSet` gives you an ability to operate with data on a bit level, it can be manipulated by standard logic operators, cloned, converted to and from basic CTS numeric data types, strings and even abstract objects. See [examples](#examples) below for more use-cases.\n\n## Keynotes\n- Platform: netstandard2.0;\n- Distributed via NuGet (check out [Menaver.NetBitSet](https://www.nuget.org/packages/Menaver.NetBitSet) and [Menaver.NetBitSet.LFSR](https://www.nuget.org/packages/Menaver.NetBitSet.LFSR))\n- The implementation is covered with both Unit (800+) and Performance (25+) tests;\n- This repository [leverages](https://github.com/Menaver/menaver.netbitset/actions) Github Actions (GHA);\n\n## Features\n- Compact storing of each individual bit in RAM;\n- Implementation of the following basic interfaces: `IEnumerable`, `ICloneable`;\n- Large data support (technically, it's up to ~18446.74 petabytes, as long as your machine's RAM can handle it :D);\n- Implicit and explicit casting operators that provide more convenient interaction with data;\n- And many others.\n\n## Supported bitwise operations\n- And\n- Or\n- Xor\n- Not (Invert)\n- Arithmetic Shift\n- Logical Shift\n- Circular Shift\n- Invert Endianess\n\n## Supported data conversions\n\n| Type                                   \t\t| From | To | Implicit Cast | Explicit Cast |\n|-----------------------------------------------|-----:| --:|--------------:|--------------:|\n| 1-bit (`bool` / `bool[]`)\t\t\t\t\t\t\t|  ✅  | ✅ |       ✅      |       ✅       |\n| 8-bits (`(s)byte` / `(s)byte[]`)\t\t\t\t\t|  ✅  | ✅ |       ✅      |       ✅       |\n| 32-bits (`(u)int` / `(u)int[]`)\t\t\t\t\t|  ✅  | ✅ |       ✅      |       ✅       |\n| 64-bits (`(u)long` / `(u)long[]`)\t\t\t\t\t|  ✅  | ✅ |       ✅      |       ✅       |\n| 64-bits floating-point (`double` / `double[]`)\t|  ✅  | ✅ |       ✅      |       ✅       |\n| String (`string`)\t\t\t\t\t\t\t\t|  ✅  | ✅ |       ✅      |       ❌       |\n| Binary string (`string`)\t\t\t\t\t\t|  ✅  | ✅ |       ✅      |       ❌       |\n| `Object` of any type (serializable)\t\t\t\t|  ✅  | ✅ |       ❌      |       ❌       |\n\n## Performance\n\nThe Performance testing is driven by [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet).\nIts run results can be found in repo's GHA [here](https://github.com/Menaver/menaver.netbitset/actions/workflows/run-perf-tests.yml).\n\n# Examples \u003ca name=\"examples\"\u003e\u003c/a\u003e\n\n### Initialization\n\n```cs\n// from bool\nNetBitSet netBitSet = false; // or new NetBitSet(false);\n\n// from byte\nNetBitSet netBitSet = (byte)42; // or new NetBitSet((byte)42);\n\n// from int\nNetBitSet netBitSet = 873; // or new NetBitSet(873);\n\n// from double\nNetBitSet netBitSet = 873.4; // or new NetBitSet(873.4);\n\n// from bytes\nNetBitSet netBitSet = new bool[] { true, false, false, true };\n\n// from bytes\nNetBitSet netBitSet = new byte[] { 34, 45, 124, 46 };\n\n// from ints\nNetBitSet netBitSet = new int[] { 34, 45, 124, 46 };\n\n// from doubles\nNetBitSet netBitSet = new double[] { 122.4, 433.2, 446.2 };\n\n// from string\nNetBitSet netBitSet = \"Hello, world!\"; // or new NetBitSet(\"Hello, world!\");\n\n// from string with encoding\nNetBitSet netBitSet = new NetBitSet(\"Hello, world!\", Encoding.ASCII);\n\n// from binary string\nNetBitSet netBitSet = \"11100110011100000\"; // or new NetBitSet(\"11100110011100000\");\n\n// from object\nNetBitSet netBitSet = new NetBitSet(DateTimeOffset.UtcNow);\n```\n\n### Conversion\n\n```cs\nvar @bool = (bool)netBitSet; // or netBitSet.ToBool()\n\nvar @byte = (byte)netBitSet; // or netBitSet.ToByte()\n\nvar @int = (int)netBitSet; // or netBitSet.ToInt()\n\nvar bools = (bool[])netBitSet; // or netBitSet.ToBools()\n\nvar bytes = (byte[])netBitSet; // or netBitSet.ToBytes()\n\nvar ints = (int[])netBitSet; // or netBitSet.ToInts()\n\nvar @string = netBitSet.ToString();\n\nvar @string = netBitSet.ToString(Encoding.ASCII);\n\nvar binaryString = netBitSet.ToBinaryString();\n\nvar dataTimeOffset = netBitSet.ToObject\u003cDateTimeOffset\u003e();\n```\n\n### Bitwise operations\n\n```cs\n// And\nnetBitSetA \u0026= netBitSetB;\n\n// Or\nnetBitSetA |= netBitSetB;\n\n// Xor\nnetBitSetA ^= netBitSetB;\n\n// Not\nnetBitSetA = ~netBitSetB;\n\n// logical shift left\nnetBitSet \u003c\u003c= 3;\n\n// logical shift right\nnetBitSet \u003e\u003e= 3;\n```\n\n### Basic use-case: visualize data\n\n```cs\n// file data to bitset\nvar bytes = File.ReadAllBytes(\"picture.png\");\nNetBitSet bits = new NetBitSet(bytes);\n\n// output binary data as string\nvar binaryString = bits.ToBinaryString();\nConsole.WriteLine(binaryString);\n```\n\n### Basic use-case: invert data bits\n\n```cs\n// file data to bitset\nvar bytes = File.ReadAllBytes(\"picture.png\");\nNetBitSet bits = new NetBitSet(bytes);\n\n// invert data bits\nbits.InvertAll();\n\n// save to file\nbytes = bits.ToBytes();\nFile.WriteAllBytes(\"picture.png\", bytes);\n```\n\n### Basic use-case: xor every bit by 0\n\n```cs\n// file data to bitset\nvar bytes = File.ReadAllBytes(\"picture.png\");\nNetBitSet bits = new NetBitSet(bytes);\n\n// xor data bits\nvar count = bits.Count;\nfor (ulong i = 0; i \u003c count; i++)\n{\n\tbits[i].Xor(Bit.False);\n}\n\n// save to file\nbytes = bits.ToBytes();\nFile.WriteAllBytes(\"picture.png\", bytes);\n```\n\n### Another use-case: symmetric bit-level data encryption using [linear-feedback shift register (LFSR)](https://en.wikipedia.org/wiki/Linear-feedback_shift_register)\n\n```cs\nvar password = \"password123\";\nvar polynomial = new ulong[] { 11, 9, 8, 0 };\n\n// password to LFSR\nvar passwordBits = new NetBitSet(password);\nvar passwordLfsr = new Menaver.NetBitSet.LFSR.LFSR(passwordBits, polynomial);\n\n// file data to bitset\nvar dataBytes = File.ReadAllBytes(\"picture.png\");\nNetBitSet dataBits = new NetBitSet(dataBytes);\n\n// encrypt data\nvar count = dataBits.Count;\nfor (ulong i = 0; i \u003c count; i++)\n{\n\tvar outBit = passwordLfsr.Shift();\n\tdataBits[i] = dataBits[i].Xor(outBit);\n}\n\n// save to file\ndataBytes = dataBits.ToBytes();\nFile.WriteAllBytes(\"picture.png\", dataBytes);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenaver%2Fmenaver.netbitset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmenaver%2Fmenaver.netbitset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenaver%2Fmenaver.netbitset/lists"}