Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- void print_binary(int x) {
- string s = "";
- int max_power = log2(x);
- cout << max_power << endl;
- for(int i = 0; i <= max_power; i++) {
- if(x & (1 << i)) {
- s += "1";
- }
- else {
- s += "0";
- }
- }
- reverse(s.begin(), s.end());
- cout << s << endl;
- }
- int main() {
- print_binary(5237);
- return 0;
- }
- // 1010001110101
- // 1010001110101
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement