十进制转换为2进制

来源:互联网 发布:虾米音乐如何解绑淘宝 编辑:程序博客网 时间:2024/06/03 19:17
/** * 思路为  *  * 模2除2 *  * @author  * */public class hex {public static void main(String[] args) {String x = Integer.toBinaryString(12);System.out.println("x:" + x);int i = 12;ArrayList<Integer> tempList = new ArrayList<Integer>();while (i > 0) {if (i == 1) {tempList.add(i);break;}tempList.add(i % 2);i = i / 2;}for (int j = tempList.size() - 1; j >= 0; j--) {System.out.print(tempList.get(j));}}}

0 0
原创粉丝点击