Skip to content

Instantly share code, notes, and snippets.

@yysaki
Last active August 29, 2015 13:56
Show Gist options
  • Save yysaki/9308510 to your computer and use it in GitHub Desktop.
Save yysaki/9308510 to your computer and use it in GitHub Desktop.
bbool型におけるビット演算の挙動を調べるプログラム
#include <iostream>
using namespace std;
int main(int argc, char const* argv[]){
bool ands[4] = {true & true, true & false, false & true, false & false};
bool ors[4] = {true | true, true | false, false | true, false | false};
cout << "ands: ";
for (int i = 0; i < 4; i++) cout << std::boolalpha << ands[i] << " ";
cout << endl;
cout << "ors: ";
for (int i = 0; i < 4; i++) cout << std::boolalpha << ors[i] << " ";
cout << endl;
bool and_substitute = true; and_substitute &= false;
bool or_substitute = true; or_substitute |= false;
cout << "and_substitute: " << std::boolalpha << and_substitute << endl;
cout << "or_substitute: " << std::boolalpha << or_substitute << endl;
return 0;
}
@yysaki
Copy link
Author

yysaki commented Mar 2, 2014

出力結果

    % g++ bitwise_operetor_about_bool_variable.cpp && ./a.out
    ands: true false false false
    ors:  true true true false
    and_substitute: false
    or_substitute:  true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment