Java Decimal to Binary dec2bin(int dec)

Here you can find the source of dec2bin(int dec)

Description

decbin

License

Open Source License

Declaration

private static String dec2bin(int dec) 

Method Source Code

//package com.java2s;
/*//www.  jav a 2 s. c o m
 * (C) Copyright IBM Corp. 2008
 *
 * LICENSE: Eclipse Public License v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    private static String dec2bin(int dec) {
        if (0 == dec)
            return "0";
        StringBuffer sb = new StringBuffer();
        while (dec != 0) {
            sb.append(1 == dec % 2 ? 1 : 0);
            dec >>= 1;
        }
        return sb.reverse().toString();
    }
}

Related

  1. dec2bin(Integer str)
  2. decimalToBinaryString(int n)
  3. decimalToBitString(int n, int min, int max)