BitSet learning

xiaoxiao2021-03-06  102

BitSet package

Use the BitSet class to include header file bitset

Here is how to use:

Operating function usage

-------------------------------------------------- -------

Is the TEST (POS) POS bit is 1 a.test (4)

ANY () is any bit is 1 A. An ()

None () is not a bit of 1 a.none ()

The count () value is a bit of 1 bit a.count ()

A.size () of the size () bit element

[POS] Access POS bit A [4]

FLIP () flips all bit A.flip ()

FLIP (POS) flip POS bit A.flip (4)

Set () 1 a.set ()

Set (POS) POS position 1 a.set (4)

RESET () Position 0 A.Reset ()

RESET (POS) POS position 0 A.Reset (4)

TO_STRING () turn bitset to string a.to_string ()

TO_ULONG () converts BitSet to ulong a.to_ulong ()

Initialization method:

BitSet <32> mybitset;

Initialize a 32-bit number, each bit is zero

BitSet <32> BitVec2 (0xfff);

000000000000000000000000000000000000111111111111111111 (Low Sixteen 1)

String Bitval ("1010");

BitSet <32> BitVec4 (Bitval);

// From the position 6, the length is 4: 1010

String Bitval ("1111110101100011010101");

BitSet <32> BitVec5 (Bitval, 6, 4);

// Start from position 6 until the string ends: 1010101

String Bitval ("1111110101100011010101");

BitSet <32> BitVec6 (Bitval, 6);

转载请注明原文地址:https://www.9cbs.com/read-104525.html

New Post(0)