Skip to content

Commit

Permalink
added bits test
Browse files Browse the repository at this point in the history
  • Loading branch information
derekmolloy committed Jun 11, 2018
1 parent 0374039 commit 56cbf68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Binary file added chp07/bits/bits
Binary file not shown.
27 changes: 27 additions & 0 deletions chp07/bits/bitsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Bits test by Derek Molloy */

#include<iostream>
#include<stdint.h>
#include<bitset>
#include<sstream>
#include<iomanip>
using namespace std;

string display(uint8_t a) {
stringstream ss;
ss << setw(3) << (int)a << "(" << bitset<8>(a) << ")";
return ss.str();
}

int main(){
uint8_t a = 25, b = 5;
cout << "A is " << display(a) << " and B is " << display(b) << endl;
cout << "A & B (AND) is " << display(a & b) << endl;
cout << "A | B (OR) is " << display(a | b) << endl;
cout << " ~A (NOT) is " << display(~a) << endl;
cout << "A ^ B (XOR) is " << display(a ^ b) << endl;
cout << "A << 1 (LSL) is " << display(a << 1) << endl;
cout << "B >> 1 (LSR) is " << display(b >> 1) << endl;
cout << "1 << 8 (LSL) is " << display(1 << 8) << endl; // ignore warning!
return 0;
}
Binary file modified chp07/test
Binary file not shown.

0 comments on commit 56cbf68

Please sign in to comment.