Java Integer to Binary integerToBinaryString(int value)

Here you can find the source of integerToBinaryString(int value)

Description

integer To Binary String

License

MIT License

Declaration

public static String integerToBinaryString(int value) 

Method Source Code

//package com.java2s;
/**//from  w w  w. j  a v a  2  s  . co  m
 * Copyright (c) 2014 Sa?l Pi?a <sauljabin@gmail.com>.
 * 
 * This file is part of GeneticAlgorithm.
 * 
 * GeneticAlgorithm is licensed under The MIT License.
 * For full copyright and license information please see the LICENSE file.
 */

public class Main {
    public static String integerToBinaryString(int value) {
        return (value < 0 ? "1" : "0")
                + Integer.toBinaryString(Math.abs(value));
    }

    public static String integerToBinaryString(int value, int size) {
        return (value < 0 ? "1" : "0")
                + String.format("%" + (size - 1) + "s",
                        Integer.toBinaryString(Math.abs(value))).replace(
                        " ", "0");
    }
}

Related

  1. int2binString(int x)
  2. integerToBin(int value)
  3. integerToBinaryString(int value, int numberOfBits)
  4. integerToBinString(final int aValue, final int aFieldWidth)
  5. intToBinary(int binary, int digits)
  6. intToBinary(int i)