Android Big Endian Convert setBigIndianInBytesArray(byte[] toPutIn, int startidx, long theNumber, int len)

Here you can find the source of setBigIndianInBytesArray(byte[] toPutIn, int startidx, long theNumber, int len)

Description

put number in array (big endian way)

Parameter

Parameter Description
toPutIn - the array to put in
startidx - start index of the num
theNumber - the number
len - the number size in bytes.

Declaration

public static void setBigIndianInBytesArray(byte[] toPutIn,
        int startidx, long theNumber, int len) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w  ww.  j  a  va2s . c om*/
     * put number in array (big endian way)
     * @param toPutIn - the array to put in
     * @param startidx - start index of the num
     * @param theNumber - the number
     * @param len - the number size in bytes.
     */
    public static void setBigIndianInBytesArray(byte[] toPutIn,
            int startidx, long theNumber, int len) {
        for (int i = 0; i < len; i++) {
            long num = (theNumber >> (8 * (len - (i + 1)))) & 0xff;
            toPutIn[i + startidx] = (byte) num;
        }
    }
}

Related

  1. getInt(byte[] data, int i, boolean bigEndian)
  2. getShort(byte[] data, int i, boolean bigEndian)
  3. switchEndian(int i)
  4. switchEndian(long l)
  5. switchEndian(short i)
  6. setLittleIndianInBytesArray(byte[] toPutIn, int startidx, long theNumber, int len)