Decimal to Binary Conversion

Decimal to Binary Conversion
SOURCE : DecimalToBinary.java


public class DecimalToBinary {

/**
* @param args
*/
public static void main(String[] args) {

DecimalToBinary db = new DecimalToBinary();

db.binar(25);

}

public void binar(int num) {

int binary[] = new int[25];

int index = 0;

while (num > 0) {

binary[index++] = num % 2;
num = num / 2;
// System.out.println(num);

}

for (int i = index - 1; i >= 0; i--) {

System.out.println(binary[i]);

}
}

}


INPUT

25



OUTPUT

1
1
0
0
1






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment