Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- std::string DecimalAsBinary(unsigned int number);
- int main()
- {
- std::cout << DecimalAsBinary(19);
- return 0;
- }
- std::string DecimalAsBinary(unsigned int number)
- {
- std::string result, mod_string;
- while (number)
- {
- mod_string = (number & 1) + '0';
- number >>= 1;
- result = result + mod_string;
- }
- std::reverse(result.begin(), result.end());
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement