Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- const long long MOD = 1e9 + 7;
- int n;
- string to_binary(int x) {
- string res = "";
- while(x > 0) {
- res += (x % 2) + '0';
- x /= 2;
- }
- while((int) res.length() < n) {
- res += "0";
- }
- reverse(res.begin(), res.end());
- return res;
- }
- int main() {
- int a = 54;
- int b = 32;
- cout << to_binary(a) << endl;
- cout << to_binary(b) << endl;
- cout << to_binary(a & b) << endl;
- cout << (a & b) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment