bit-manipulation
🛠️ A C++23 header-only bit manipulation library supporting getting, setting, clearing, filling and combining bits.(使用C++23开发的比特位操作库,支持获取、设置、清除、填充和组合操作。)
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.9%) to scientific vocabulary
Keywords
Repository
🛠️ A C++23 header-only bit manipulation library supporting getting, setting, clearing, filling and combining bits.(使用C++23开发的比特位操作库,支持获取、设置、清除、填充和组合操作。)
Basic Info
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
Bit Manipulation
Introduction
A header-only bit manipulation library written in C++23, supporting:
- Getting bits, bytes, words or double words in an integral value.
- Clearing bits, bytes, words or double words in an integral value.
- Setting bits, bytes, words or double words in an integral value.
- Filling bits, bytes, words or double words in an integral value.
- Combining bits, bytes, words or double words to a larger integral value.
- Writing or reading bytes of an integral or a float value using the specified endianness.
Unit Tests
Prerequisites
- Install GoogleTest.
- Install CMake.
Building
Go to the project folder and run:
bash
mkdir -p build
cd build
cmake -DBIT_MANIP_BUILD_TESTS=ON ..
cmake --build .
Running
Go to the build folder and run:
bash
ctest -VV
Examples
See more examples in tests/bit_manip_tests.cpp.
c++
// Get the specified bits in an integral value.
constexpr std::uint32_t val {0x12345678};
EXPECT_EQ(GetBits(val, 0, sizeof(std::uint8_t) * CHAR_BIT), 0x78);
EXPECT_EQ(GetBits(val, 0, sizeof(std::uint16_t) * CHAR_BIT), 0x5678);
c++
// Set the value of the specified bits in an integral value.
std::uint32_t val {0x12345678};
SetBits(val, 0xFFFF, 0, sizeof(std::uint16_t) * CHAR_BIT);
EXPECT_EQ(val, 0x1234FFFF);
c++
// Fill the specified bits in an integral value.
std::uint32_t val {0x12345678};
FillBits(val, 0, sizeof(std::uint8_t) * CHAR_BIT);
EXPECT_EQ(val, 0x123456FF);
c++
// Clear the specified bits in an integral value.
std::uint32_t val {0x12345678};
ClearBits(val, 0, sizeof(std::uint16_t) * CHAR_BIT);
EXPECT_EQ(val, 0x12340000);
c++
// Combine low bits and high bits into a new integral value.
EXPECT_EQ((CombineBits<std::uint16_t, std::uint8_t>(0x12, 0x34)), 0x1234);
EXPECT_EQ((CombineBits<std::uint32_t, std::uint16_t>(0x1234, 0x5678)), 0x12345678);
c++
// Check if a bit is set in an integral value.
constexpr std::uint8_t val {0b0000'0001};
EXPECT_TRUE(IsBitSet(val, 0));
EXPECT_FALSE(IsBitSet(val, 1));
c++
// Read bytes using the specified endianness.
constexpr int buf {0x12345678};
int val {0};
ReadBytes(std::as_bytes(std::span {&buf, 1}), val, GetOppositeEndian());
EXPECT_EQ(val, std::byteswap(buf));
License
Distributed under the MIT License. See LICENSE for more information.
Owner
- Name: Zhuagenborn
- Login: Zhuagenborn
- Kind: organization
- Location: Ireland
- Repositories: 3
- Profile: https://github.com/Zhuagenborn
Software Development | Artificial Intelligence | Reverse Engineering.
Citation (CITATION.cff)
cff-version: 1.2.0 authors: - family-names: Chen given-names: Zhenshuo orcid: https://orcid.org/0000-0003-2091-4160 - family-names: Liu given-names: Guowen orcid: https://orcid.org/0000-0002-8375-5729 title: Bit Manipulation date-released: 2024-07-20 url: https://github.com/Zhuagenborn/Bit-Manipulation
GitHub Events
Total
- Push event: 37
Last Year
- Push event: 37
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout main composite
- actions/download-artifact main composite
- actions/upload-artifact main composite