Java Utililty Methods Binary to Int

List of utility methods to do Binary to Int

Description

The list of methods to do Binary to Int are organized into topic(s).

Method

intbin2int(byte[] array, int offset)
binint
return ((array[offset + 0] & 0xff) << 24) + ((array[offset + 1] & 0xff) << 16)
        + ((array[offset + 2] & 0xff) << 8) + (array[offset + 3] & 0xff);
StringbinaryToInt(String binary, int intlength)
binary To Int
String s = Integer.parseInt(binary, 2) + "";
while ((s + "").length() < intlength) {
    s = "0" + s;
return s;
intbinaryToInt(String binaryValue, boolean signIncluded)
This method converts String that contains a binary to int.
boolean isNegative = false;
int value = 0;
if (signIncluded) {
    if (binaryValue.charAt(0) == '1') {
        isNegative = true;
        binaryValue = binaryValue.replace('1', '2');
        binaryValue = binaryValue.replace('0', '1');
        binaryValue = binaryValue.replace('2', '0');
...
longbinaryToLong(String bin)
A quick method to convert bin, a binary representation, to an integer number.
boolean validBinary = true;
char[] binArray = bin.toCharArray();
for (int i = 0; validBinary && i < binArray.length; i++) {
    if (binArray[i] != '0' || binArray[i] != '1')
        validBinary = false;
if (validBinary)
    return Long.parseLong(bin, 2);
...
intbinToDec(String str)
bin To Dec
int result = 0;
for (int i = 0; i < str.length(); i++) {
    if (str.charAt(i) != '0' && str.charAt(i) != '1') {
        return -1;
    result = result * 2 + str.charAt(i) - '0';
return result;
...
intboolean2integer(boolean b)
booleaninteger
return b ? -1 : 0;
intboolean2integer(boolean b)
Converts a Boolean value to an Integer value.
return b ? -1 : 0;