Guest User

Untitled

a guest
Apr 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int power2(int i){
  6. int res=1;
  7. while(i-->0){
  8. res = res*2;
  9. }
  10. return res;
  11. }
  12.  
  13. string dec2bin(int n){
  14. string res;
  15. while(n>0){
  16. if (n%2>0)
  17. res += "1";
  18. else
  19. res += "0";
  20. n /= 2;
  21. }
  22. return res;
  23. }
  24.  
  25. int main(void){
  26. cout << "Test: " << dec2bin(2894);
  27. }
Add Comment
Please, Sign In to add comment