Two Bytes To Integer : Integer « Date Type « Android

Two Bytes To Integer


 * This file is part of JSTUN. 
 * Copyright (c) 2005 Thomas King <> - All rights
 * reserved.
 * This software is licensed under either the GNU Public License (GPL),
 * or the Apache 2.0 license. Copies of both license agreements are
 * included in this distribution.
class Main{

  public static final int twoBytesToInteger(byte[] value) throws UtilityException {
    if (value.length < 2) {
      throw new UtilityException("Byte array too short!");
        int temp0 = value[0] & 0xFF;
        int temp1 = value[1] & 0xFF;
        return ((temp0 << 8) + temp1);

class UtilityException extends Exception {
  private static final long serialVersionUID = 3545800974716581680L;

  UtilityException(String mesg) {



Related examples in the same category

1.Integer To One Byte
2.Integer To Two Bytes
3.Integer To Four Bytes
4.One Byte To Integer
5.List to int[]
6.Tests if an integer is power of two
7.Convert an integer value to its byte array representation
8.Convert a byte array integer (4 bytes) to its int value
9.Convert a byte array representing an unsigned integer (4bytes) to its long value
10.fahrenheit To Celsius, celsius To Fahrenheit
11.Padding Int value