[ create a new paste ] login | about

Link: http://codepad.org/PBxWQChC    [ raw code | output | fork ]

C++, pasted on Apr 24:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std;

string dec2bin(int value){
    string out;
    do
	{
        out.insert(0, (const char *)((value & 0x01) ? "1" : "0"), 1);
    }
    while( value >>= 1 );
    return out;
}

int main(){
    cout<<dec2bin(235)<<endl;
    return 0;
}


Output:
1
11101011


Create a new paste based on this one


Comments: