tbits.cpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 33 行

CPP
33
字号
// tbits.cpp:	Test the bits class

#include <iostream.h>
#include <iomanip.h>
#include "bits.h"

main()
{
    int i;
    dbits x(5), y, null; // grb

    cout << "Initial x: " << x << endl;

    for (i = 0; i <= 5; ++i)
        x.set(i);
    cout << "x: " << x << " (" << x.count() << " bits set)" << endl;
    cout << "x == 3f? " << (x == 0x3f) << endl;
    cout << "x <<= 3 = " << (x <<= 3) << endl;
    cout << "x >>= 3 = " << (x >>= 3) << endl;
    cout << "x ^ 3 = " << (x ^ 3) << endl;
    cout << "x & 3 = " << (x & 3) << endl;
    cout << "3 & x = " << (((dbits)(3)) & x) << endl; //grb
    cout << "~x = " << ~x << endl;
        
    for (i = 4; i <= 12; ++i)
        y.set(i);
    cout << "y: " << y << " (" << y.count() << " bits set)" << endl;
    cout << "x & y = " << (x & y) << endl;
    cout << "x | y = " << (x | y) << endl;
    cout << "x ^ y = " << (x ^ y) << endl;
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?