Without further ado, here it goes:
===========================
package binaryconverter;
import java.util.ArrayList;
/**
*
* @author marcossilvestri
*/
public class BinaryConverter {
public static void main(String[] args) {
int dividend = 23;
int divisor = 2;
int quotient = 0;
int remainder = 0;
ArrayList result = new ArrayList();
remainder = dividend % divisor;
quotient = dividend / divisor;
result.add(remainder);
do {
remainder = quotient % divisor;
quotient /= divisor;
result.add(remainder);
} while (quotient != 0);
int i = result.size() - 1;
while (i >= 0) {
System.out.print(result.get(i));
i--;
}
System.out.println();
}
}
===========================
Catch you later!
No comments:
Post a Comment