Java Byte Array to Int byteToInt(byte[] i_Value)

Here you can find the source of byteToInt(byte[] i_Value)

Description

byte To Int

License

Open Source License

Declaration

public static int byteToInt(byte[] i_Value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static int byteToInt(byte[] i_Value) {
        if (i_Value.length >= 4) {
            return (((i_Value[0] & 0xFF) << 24) + ((i_Value[1] & 0xFF) << 16) + ((i_Value[2] & 0xFF) << 8)
                    + ((i_Value[3] & 0xFF) << 0));
        } else if (i_Value.length == 3) {
            return (((i_Value[0] & 0xFF) << 16) + ((i_Value[1] & 0xFF) << 8) + ((i_Value[2] & 0xFF) << 0));
        } else if (i_Value.length == 2) {
            return (((i_Value[0] & 0xFF) << 8) + ((i_Value[1] & 0xFF) << 0));
        } else if (i_Value.length == 1) {
            return (((i_Value[0] & 0xFF) << 0));
        } else {/* w w w .  j ava  2 s  .c  om*/
            return 0;
        }
    }
}

Related

  1. byteToInt(byte[] b)
  2. byteToInt(byte[] bank)
  3. byteToInt(byte[] buf, int off)
  4. byteToInt(byte[] byteArray)
  5. byteToInt(byte[] bytes)
  6. byteToInt(byte[] num)
  7. byteToInt(byte[] source, int sourceOffset)
  8. byteToInt(byte[] values)
  9. byteToInt(final byte[] b)