std::bitset...or&=,|=,^=,~(3)
π std::bitset::operator&=,|=,^=,~ π
okay bestie, welcome to the <bitset> operator page from the C++ Standard Libary π β the header files it under std::bitset...or&=,|=,^=,~(3), and we are keeping every funky character. This one is all about smashing bits together with binary AND, OR, XOR, and NOT. periodt. β¨
πΈ NAME πΈ
std::bitset::operator&=,|=,^=,~ - std::bitset::operator&=,|=,^=,~
β¨ Synopsis β¨
bitset& operator&=( const bitset& other ); (1) (noexcept since C++11) (constexpr since C++23)
bitset& operator|=( const bitset& other ); (2) (noexcept since C++11) (constexpr since C++23)
bitset& operator^=( const bitset& other ); (3) (noexcept since C++11) (constexpr since C++23)
bitset operator~() const; (4) (noexcept since C++11) (constexpr since C++23)
This crew performs binary AND, OR, XOR and NOT. π«Ά
- Sets the bits to the result of binary AND on corresponding pairs of bits of
*thisandother. - Sets the bits to the result of binary OR on corresponding pairs of bits of
*thisandother. - Sets the bits to the result of binary XOR on corresponding pairs of bits of
*thisandother. - Returns a temporary copy of
*thiswith all bits flipped (binary NOT).
π¨ Note that&=,|=, and^=are only defined for bitsets of the same sizeN. Same size or itβs not it, bestie.
π Parameters π
otherβ another bitset
π Return value π
1-3)β*this4)βstd::bitset<N>(*this).flip()
π¦ Example π¦
Run this code, bestie:
// Run this code
#include <bitset>
#include <cstddef>
#include <iostream>
#include <string>
int main()
{
const std::string pattern_str{"1001"};
std::bitset<16> pattern{pattern_str}, dest;
for (std::size_t i = dest.size() / pattern_str.size(); i != 0; --i)
{
dest <<= pattern_str.size();
dest |= pattern;
std::cout << dest << " (i = " << i << ")\n";
}
std::cout << ~dest << " (~dest)\n";
}
π Output π
0000000000001001 (i = 4)
0000000010011001 (i = 3)
0000100110011001 (i = 2)
1001100110011001 (i = 1)
0110011001100110 (~dest)
π₯ See also π₯
operator<<=,operator>>=β performs binary shift left and shift rightoperator<<β (public member function)operator>>
mwah π β source: http://cppreference.com, version/date: 2024.06.10, page: std::bitset...or&=,|=,^=,~(3). slay and stay bitwise, bestie ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms