十进制转换二进制

 

private static String convertBinary(int sum) {
        StringBuffer binary = new StringBuffer();
        while (true) {
            binary.insert(0, sum % 2);
            
            sum = sum / 2;
            if (sum == 0 ) {
              break;
            } else if (sum == 1) {
                binary.insert(0, sum % 2);
                break;
            }
        }
        return binary.toString();
    }

 

Anti-code complement the original code

  

  

posted @ 2017-12-03 08:53  apanda009  阅读(173)  评论(0编辑  收藏  举报