operator&,|,^(std::bitset)
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| (1) | ||
template< std::size_t N > bitset<N> operator&( const bitset<N>& lhs, const bitset<N>& rhs ); |
(C++11未満) | |
template< std::size_t N > bitset<N> operator&( const bitset<N>& lhs, const bitset<N>& rhs ) noexcept; |
(C++11以上) | |
| (2) | ||
template< std::size_t N > bitset<N> operator|( const bitset<N>& lhs, const bitset<N>& rhs ); |
(C++11未満) | |
template< std::size_t N > bitset<N> operator|( const bitset<N>& lhs, const bitset<N>& rhs ) noexcept; |
(C++11以上) | |
| (3) | ||
template< std::size_t N > bitset<N> operator^( const bitset<N>& lhs, const bitset<N>& rhs ); |
(C++11未満) | |
template< std::size_t N > bitset<N> operator^( const bitset<N>& lhs, const bitset<N>& rhs ) noexcept; |
(C++11以上) | |
2つのビットセット lhs と rhs の間でバイナリ論理積、論理和、排他的論理和を行います。
1)
lhs と rhs の対応するビットの組に対するバイナリ論理積の結果を格納する bitset<N> を返します。2)
lhs と rhs の対応するビットの組に対するバイナリ論理和の結果を格納する bitset<N> を返します。3)
lhs と rhs の対応するビットの組に対するバイナリ排他的論理和の結果を格納する bitset<N> を返します。引数
| lhs | - | 演算子の左側のビットセット |
| rhs | - | 演算子の右側のビットセット |
戻り値
1)
bitset<N>(lhs) &= rhs2)
bitset<N>(lhs) |= rhs3)
bitset<N>(lhs) ^= rhs例
Run this code
#include <bitset>
#include <iostream>
int main()
{
std::bitset<4> b1("0110");
std::bitset<4> b2("0011");
std::cout << "b1 & b2: " << (b1 & b2) << '\n';
std::cout << "b1 | b2: " << (b1 | b2) << '\n';
std::cout << "b1 ^ b2: " << (b1 ^ b2) << '\n';
}
出力:
b1 & b2: 0010
b1 | b2: 0111
b1 ^ b2: 0101
関連項目
| バイナリ論理積、論理和、排他的論理和、論理否定を行います (パブリックメンバ関数) |