Java Integer Create ToInt(short n1, short n2)

Here you can find the source of ToInt(short n1, short n2)

Description

To Int

License

Apache License

Declaration

public static int ToInt(short n1, short n2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int ToInt(short n1, short n2) {
        byte[] bytes = new byte[4];
        bytes[1] = (byte) (n1 & 0xff);
        bytes[0] = (byte) ((n1 >> 8) & 0xff);
        bytes[3] = (byte) (n2 & 0xff);
        bytes[2] = (byte) ((n2 >> 8) & 0xff);

        return ToInt(bytes);
    }/*from  w w  w .  j a va 2  s  .c  o m*/

    public static int ToInt(byte bytes[]) {
        return (bytes[3] & 0xff | (bytes[2] & 0xff) << 8
                | (bytes[1] & 0xff) << 16 | (bytes[0] & 0xff) << 24);
    }

    public static int ToInt(byte bytes[], int offset) {
        return (bytes[offset + 3] & 0xff | (bytes[offset + 2] & 0xff) << 8
                | (bytes[offset + 1] & 0xff) << 16 | (bytes[offset] & 0xff) << 24);
    }
}

Related

  1. toInt(Object value)
  2. toInt(Object value, int defaultValue)
  3. toInt(Object value, int nullValue)
  4. toInt(Object vo)
  5. toInt(short leftShort, short rightShort)
  6. toInt(short s0, short s1)
  7. toInt(short x, short y)
  8. toInt(short[] arr)
  9. toInt(String arr, String separator)