1. 소개
- 자바에서 10진수를 2진수로 변경하는 방법이다.
- 자리수를 지정하여 0을 패딩할 수 있다.
2. 코드
StringBuffer deciFormat = new StringBuffer();
for ( int inx=0; inx<n; inx++ ) {
deciFormat.append("0");
}
System.out.println(i);
String s1 = Integer.toBinaryString(i);
System.out.println(s1);
DecimalFormat df = new DecimalFormat(deciFormat.toString());
String s2 = df.format(Integer.parseInt(s1));
System.out.println(s2);
3. 결과
9 1001 01001