Cpp-standard-library-cpp-bitset-operator-bitwise-and
提供:Dev Guides
C ++ビットセットライブラリ-operator&関数
説明
- C ++関数* std
- bitset :: operator&*は、ビットセットに対してビット単位のAND演算を実行します。
宣言
- 以下は、std
- bitsetヘッダーからのstd :: bitset :: operator&関数の宣言です。
C 98
template<size_t N>
bitset<N> operator& (const bitset<N>& first, const bitset<N>& second);
C 11
template<size_t N>
bitset<N> operator& (const bitset<N>& first, const bitset<N>& second) noexcept;
パラメーター
- first -最初のビットセットオブジェクト。
- second -2番目のビットセットオブジェクト。
戻り値
ビット単位のAND演算の結果を含むビットセットを返します。
例外
このメンバー関数は例外をスローしません。
例
- 次の例は、std
- bitset :: operator&関数の使用法を示しています。
#include <iostream>
#include <bitset>
using namespace std;
int main(void) {
bitset<4> b("1010");
bitset<4> mask("1000");
/*Trun off all bits except 3rd bit*/
auto result = b & mask;
cout << result << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
1000