Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- template <typename X>
- inline X abs(const X &a) { return a < 0 ? -a : a; }
- int main()
- {
- int a; cin >> a;
- cout << "abs: " << abs(a) << endl;
- cout << "int: " << a << endl;
- cout << "binary abs: ";
- for(int i = 7;i>=0;i--)
- cout<< bool(abs(a)&(1<<i));
- cout << endl;
- cout << "binary: ";
- for(int i = 7;i>=0;i--)
- cout<< bool(a&(1<<i));
- cout << endl;
- cout.setf(ios::showbase);
- cout << "hex: " << hex << int(char(a));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement