C ++ bitset

Source: Internet
Author: User

Bitset is a container that can store binary data.

Major bitset operations include:


(Constructor)
Construct bitset (Public member function) // construct the bitset... format: bitset <length> name
Applicable Operators
Bitset operators (functions) // you can directly perform binary operations on the bitset container, such as ^, | ,~, <,> And so on
OPERATOR []
Access bit (Public member function) // values can be assigned as arrays. Bitset <4> B; B [0] = 1;
Set
Set bits (Public member function) // by default, all values in the container are assigned as 1, and specific positions can be assigned to specific values.
Such as bitset <4> B; B. Set (); // 1111. B. Set (1011.
Reset
Reset bits (Public member function) // by default, all values in the container are assigned 0 values. You can also assign specific values to specific locations.
Flip
Flip bits (Public member function) // by default, the number in the container is reversed, 1 is changed to 0, 0 is changed to 1, you can also reverse bitset <4> B (string ("0001"); B. file (2); // 0101; B. file ();
// 1010
To_ulong
Convert to unsigned long integer (Public member function) // convert the container value to a decimal number.
To_string
Convert to string (Public member function) // convert the container's tired value into a string
Count
Count Bits Set (Public member function) // count the number of 1 in the container
Size
Return size (Public member function) // container size
Test
Return bit value (Public member function) // returns the number at each position.
Any
Test if any bit is set (Public member function) // if the container value is greater than 0, the system returns true.
None
Test if no bit is set (Public member function) // and any get the inverse. The container value = 0 returns true. Otherwise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.