[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/dst/cpp-lib/master/src/bit.cpp [Back]  [Original]

/*
 * bitlib.cpp
 *
 *  Created on: Nov 2, 2013
 *      Author: dst
 */

#include 
#include 
#include 
#include 
using namespace std;

using std::bitset;

inline void bit() {
    // bitset
    bitset empty;
    assert(empty[0] == false);
    assert(empty[9] == false);
    
    // initialize from string
    bitset second("01011");
    // second is 0000001011
    assert(second.to_ulong() == 11);

    // bitset stores bits in reverse order
    bitset bits;         // 0000
    assert(bits.to_ulong() == 0);
    bits[1]= 1;           // 0010
    assert(bits.to_ulong() == 2);
    bits[2]= 1;           // 0110
    assert(bits.to_ulong() == 6);
    
    // bit operations
    assert(1 

Web Proxy Viewer  |  New URL  |  Original Page