Android Int to Byte Array Convert getAs_uint16_NetOrder(int theNumber)

Here you can find the source of getAs_uint16_NetOrder(int theNumber)

Description

turn 16 bits unsigned integer number to byte array representing the number in network order.

Parameter

Parameter Description
theNumber a parameter

Return

byte array (int in java is 4 bytes here only the lower 2 bytes are counted)

Declaration

public static byte[] getAs_uint16_NetOrder(int theNumber) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from www.  j  a  va  2  s  . c  om*/
     * turn 16 bits unsigned integer number to byte array representing the number
     *  in network order.
     * @param theNumber
     * @return byte array 
     *  (int in java is 4 bytes here only the lower 2 bytes are counted)
     */
    public static byte[] getAs_uint16_NetOrder(int theNumber) {
        byte[] toReturn = new byte[2];

        toReturn[0] = (byte) (theNumber & 0xf0);
        toReturn[1] = (byte) (theNumber & 0x0f);

        return toReturn;
    }
}

Related

  1. toByteArray(int in, int outSize)
  2. toByteArray(int val, byte[] b, int pos)
  3. ints2bytesBE(int[] val)
  4. ints2bytesLE(int[] val)
  5. intsToBytes(int[] values)
  6. getAs_uint32_NetOrder(int theNumber)
  7. toBytes(int integer, byte[] output, int offset)
  8. int2ByteArray(int num)
  9. int2ByteArrayBigEndian(int num)