Code Monkey home page Code Monkey logo

bitset_ex's Introduction

bitset_ex

a C++ bitset class which allows set bit-number during run time. As know, the standard C++ doesn't support init a bitset class during runtime using a runtime result.

interface

  1. set(const int bitpos) - set the given bitpos to 1, if the parameter is -1, set all bit to 1

  2. reset(const int bitpos, const bool value) - set the given bitpos to the given value (0 or 1)

  3. test(const int bitpos) - try to get the bit value, true for 1, and false for 0

  4. operator(const int bitpos) - the same as the function test(..)

  5. print() - output the bitset, the output format is controlled by function set_output_format(...)

  6. set_output_format(const int cluster_bit_size) - set output format

  7. operator[] - set to true or set to false

please contact [email protected] or xgzhang at seu.edu.cn if you have any question to use the class.

A simple example

int main()
{
   bitset_ex bs(7);
    bs.set();
    bs.set_output_format(4);
    bs.print();

    bs.set(3);
    bs.reset(2);
    bs.reset(4);
    bs.print();

    bs[2] = true;
    bs[3] = false;
    bs.print();

    if(bs.test(2))
        cout<<"good"<<endl;
    else
        cout<<"bad"<<endl;
}

bitset_ex's People

Contributors

zxg519 avatar

Stargazers

 avatar

Watchers

 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.