Question: I need to convert 2 byte array ( byte[2] ) to integer value in java. How can I do that?

Answer: 
You can use [`ByteBuffer`](http://download.oracle.com/javase/6/docs/api/java/nio/ByteBuffer.html) for this:

```
ByteBuffer buffer = ByteBuffer.wrap(myArray);
buffer.order(ByteOrder.LITTLE_ENDIAN);  // if you want little-endian
int result = buffer.getShort();

```

See also [Convert 4 bytes to int](https://stackoverflow.com/q/2383265/139010).
Well, each byte is an integer in the range -128..127, so you need a way to map a pair of integers to a single integer. There are many ways of doing that, depending on what you have encoded in the pair of bytes. The most common will be storing a 16-bit signed integer as a pair of bytes. Converting that back to an integer depends on whether you store it big-endian form:

```
(byte_array[0]<<8) + (byte_array[1] & 0xff)

```

or little endian:

```
(byte_array[1]<<8) + (byte_array[0] & 0xff)

```