[ create a new paste ] login | about

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

salvador@conclase.net - C++, pasted on Nov 13:
// Decimal a binario
// (C) 2009 Con Clase
// Salvador Pozo
#include <iostream>

using namespace std;

void DecimalBinario(int, int);

int main() {

    DecimalBinario(65536,2);
    cout << endl;
    DecimalBinario(65536,3);
    cout << endl;
    DecimalBinario(65536,8);
    cout << endl;
    DecimalBinario(65536,10);
    cout << endl;
    DecimalBinario(65536,16);
    cout << endl;
    return 0;
}

void DecimalBinario(int n, int base) {
    if(n >= base) DecimalBinario(n/base, base);
    cout << char((n%base < 10) ? '0'+n%base : 'A'+n%base-10);
}


Output:
1
2
3
4
5
10000000000000000
10022220021
200000
65536
10000


Create a new paste based on this one


Comments: