Friday, January 29, 2016

Decimal to Binary conversion

Decimal to Binary conversion


Convert given number in decimal to binary. for example, given decimal number is 11 then output is 1011 in binary.
Sol:
1
2
3
4
5
6
7
8
void DecimalToBinary(int n)
{
    if(n>0)
    {
        DecimalToBinary(n/2);
        System.out.print(n%2);
    }
}

No comments:

Post a Comment