aaronhma

Expanded Form of A Number

May 18th, 2022 (edited)
772
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void print(int n)
  6. {
  7.   vector<int> ans;
  8.  
  9.   while (n) {
  10.     ans.push_back(n & 1);
  11.     n >>= 1;
  12.   }
  13.  
  14.   for (int i = 0; i < (int)ans.size(); i++)
  15.     if (ans[i])
  16.       cout << (1 << i) << " ";
  17.  
  18.   cout << "\n";
  19. }
  20.  
  21. int main()
  22. {
  23.   print(0b110100);
  24.  
  25.   return 0;
  26. }
RAW Paste Data Copied