Android Int to Byte Array Convert getAs_uint32_NetOrder(int theNumber)

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

Description

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

Parameter

Parameter Description
theNumber a parameter

Return

byte array

Declaration

public static byte[] getAs_uint32_NetOrder(int theNumber) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  w w  .  ja va  2  s.  c o m
     * turn 32 bits unsigned integer number to byte array representing the number
     *  in network order.
     * @param theNumber
     * @return byte array 
     */
    public static byte[] getAs_uint32_NetOrder(int theNumber) {
        byte[] toReturn = new byte[4];

        toReturn[0] = (byte) ((theNumber >> 24) & 0xff0);
        toReturn[1] = (byte) ((theNumber >> 16) & 0xff);
        toReturn[2] = (byte) ((theNumber >> 8) & 0xff);
        toReturn[3] = (byte) (theNumber & 0xff);

        return toReturn;
    }
}

Related

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