e04-04.cpp

来自「游戏开发数据结构-Data.Structures.for.Game.Progra」· C++ 代码 · 共 41 行

CPP
41
字号
// =======================================================
//  Chapter 4, Example 1
//  The Bitvector Class
// =======================================================
#include "Bitvector.h"



void main()
{
    // create a bitvector with 32 bits.
    Bitvector bitv( 32 );

    bool b;

    // set index 0 to true, and retrieve it again.
    bitv.Set( 0, true );
    b = bitv[0];

    // set index 31 to false, and retrieve it again.
    bitv.Set( 31, false );
    b = bitv[31];

    // set all the bits in the vector to 0
    bitv.ClearAll();

    // set all the bits in the vector to 1
    bitv.SetAll();

    // resize the bitvector to 48 bits
    bitv.Resize( 48 );

    // get the size of the bitvector.
    int s = bitv.Size();

    // Why is s = 64? Remember, since we are on a 32 bit system, 
    // we can only have multiples of 32. Since we asked for 48
    // bits, the resize algorithm had to make enough room for 48 bits,
    // so it jumped up to the next level and made 64.

}

⌨️ 快捷键说明

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