avr39ripe

cppBitoperatorsBasics

Jun 8th, 2021
1,810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     uint8_t byteA{ 0b00001010 };
  6.     uint8_t byteB{ 0b01011011 };
  7.    
  8.     uint8_t res{ 0b01010001 };
  9.     // 0b00001010
  10.     // 0b01011011
  11.     // 0b01010001
  12.    
  13.  
  14.     //  a   b   a ^ b
  15.     //  0   0   0
  16.     //  1   0   1
  17.     //  0   1   1
  18.     //  1   1   0
  19.  
  20.  
  21.     byteA = (byteA ^ byteB);
  22.     //byteA = (byteA && byteB);
  23.     //byte = !byte;
  24.  
  25.     std::cout << ((int)byteA) << '\n';
  26.  
  27.     std::cout << (byteA == res) << '\n';
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment