Namespaces
Variants

std::bitset<N>:: operator&=,|=,^=,~

From cppreference.net
Utilities library
bitset & operator & = ( const bitset & other ) ;
(1) (C++11부터 noexcept)
(C++23부터 constexpr)
bitset & operator | = ( const bitset & other ) ;
(2) (C++11부터 noexcept)
(C++23부터 constexpr)
bitset & operator ^ = ( const bitset & other ) ;
(3) (C++11부터 noexcept)
(C++23부터 constexpr)
bitset operator~ ( ) const ;
(4) (C++11부터 noexcept)
(C++23부터 constexpr)

이진 AND, OR, XOR 및 NOT 연산을 수행합니다.

1) 해당 비트들을 * this other 의 대응되는 비트 쌍에 대한 이진 AND 연산 결과로 설정합니다.
2) 해당 비트 쌍에 대해 * this other 의 이진 OR 연산 결과로 비트들을 설정합니다.
3) 해당 비트들을 * this other 의 대응되는 비트 쌍에 대한 이진 XOR 연산 결과로 설정합니다.
4) 모든 비트가 반전된(이진 NOT) * this 의 임시 복사본을 반환합니다.

&= , |= , 그리고 ^= 연산자는 동일한 크기 N 의 bitset에 대해서만 정의된다는 점에 유의하십시오.

목차

매개변수

other - another bitset

반환값

1-3) * this
4) std:: bitset < N > ( * this ) . flip ( )

예제

#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";
}

출력:

0000000000001001 (i = 4)
0000000010011001 (i = 3)
0000100110011001 (i = 2)
1001100110011001 (i = 1)
0110011001100110 (~dest)

참고 항목

이진 왼쪽 시프트 및 오른쪽 시프트 수행
(public member function)