Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int power2(int i){
- int res=1;
- while(i-->0){
- res = res*2;
- }
- return res;
- }
- string dec2bin(int n){
- string res;
- while(n>0){
- if (n%2>0)
- res += "1";
- else
- res += "0";
- n /= 2;
- }
- return res;
- }
- int main(void){
- cout << "Test: " << dec2bin(2894);
- }
Add Comment
Please, Sign In to add comment