Created
July 21, 2021 04:19
-
-
Save jstaursky/278cde13a1cceace28b3009749cc4084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <cstdint> | |
#include <fmt/format.h> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
uint8_t a = 0b1111'0000; | |
auto b = vector<uint8_t> {a,a,a,a,a,a,a,a,a}; | |
auto c = b; | |
auto d = c; | |
fmt::print (" {:b}\n\n", a); | |
// bit clearing | |
for (int i = 0; i != 8; ++i) { | |
b[i] &= ~(1 << i); | |
fmt::print("{} {:8b} \n", i , b[i]); | |
} | |
fmt::print("\n"); | |
// bit flipping | |
for (int i = 0; i != 8; ++i) { | |
c[i] ^= (1 << i); | |
fmt::print("{} {:8b} \n", i , c[i]); | |
} | |
fmt::print("\n"); | |
// bit setting | |
for (int i = 0; i != 8; ++i) { | |
d[i] |= (1 << i); | |
fmt::print("{} {:8b} \n", i , d[i]); | |
} | |
return 0; | |
} | |
// g++ -std=c++17 test.cpp -lfmt -o test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment