Advertisement
Guest User

Untitled

a guest
May 30th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <algorithm>
  6.  
  7. std::string DecimalAsBinary(unsigned int number);
  8.  
  9. int main()
  10. {
  11.   std::cout << DecimalAsBinary(19);
  12.   return 0;
  13. }
  14.  
  15. std::string DecimalAsBinary(unsigned int number)
  16. {
  17.   std::string result, mod_string;
  18.   while (number)
  19.     {
  20.       mod_string = (number & 1) + '0';
  21.       number >>= 1;
  22.       result = result + mod_string;
  23.     }
  24.   std::reverse(result.begin(), result.end());
  25.   return result;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement