Giter VIP home page Giter VIP logo

bitstring's Introduction

C++ bitstring

WIP C++17 library to handle sequences of bits (similar to std::vector). It allows for creation, concatenation, splitting, iteration etc. of bit-sequences.

The library is mainly used by me to write unittests for embedded system code, therefore performance is not optimized in many places.

A big inspiration for the interface was the bitstring python library I greatly enjoy (see https://bitstring.readthedocs.io/en/latest/index.html). While python bitstring was a big inspiration, C++ bitstring is not a carbon copy and behavior differs in places especially to comply with C++ conventions.

Using the library

The easiest way is to integrate bitstring into your build via cmake CPM:

CPMAddPackage("gh:andreasWallner/bitstring@<version>")

Example

#include "bitstring.hpp"

void foo() {
  using namespace bitstring;

  // generate 10 bit sequence by parsing string
  auto const header = "0b1101000101"_ba;
  // generate 14 bit sequence from integer
  auto const data = bit_array(0xabcdU, 14);
  // generate 16 bit sequence from integer, but add MSB-first
  auto const footer = bit_array(uint16_t{0x1234U}, bitorder::msb_first);

  // concatenate all 3 (yes operator+ is currently missing)
  auto packet = bit_array(header).append(data).append(footer);

  // print concatenated sequence
  std::cout << packet.bin();
}

Development notes

To easily run clang-tidy during the build set BITSTRING_CLANG_TIDY to you clang-tidy. You can also set it to e.g. clang-tidy-10;-fix to automatically apply fixes during the build.

bitstring's People

Contributors

andreaswallner avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.