Java Long to long2Arr(long var, byte[] arrayBytes, int startIndex)

Here you can find the source of long2Arr(long var, byte[] arrayBytes, int startIndex)

Description

Write the bytes of "var" into new byte array.

License

Open Source License

Parameter

Parameter Description
var the long of 8 bytes to encode return tmp The byte array to store into.

Declaration

public static void long2Arr(long var, byte[] arrayBytes, int startIndex) 

Method Source Code

//package com.java2s;
/* DielmoOpenLiDAR/*from   ww w.  j  a  v a  2 s . c o  m*/
 *
 * Copyright (C) 2008 DIELMO 3D S.L. (DIELMO) and Infrastructures  
 * and Transports Department of the Valencian Government (CIT)
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * For more information, contact:
 *
 * DIELMO 3D S.L.
 * Plaza Vicente Andr?s Estell?s 1 Bajo E
 * 46950 Xirivella, Valencia
 * SPAIN
 *   
 * +34 963137212
 * dielmo@dielmo.com
 * www.dielmo.com
 * 
 * or
 * 
 * Generalitat Valenciana
 * Conselleria d'Infraestructures i Transport
 * Av. Blasco Ib??ez, 50
 * 46010 VALENCIA
 * SPAIN
 *
 * +34 963862235
 * gvsig@gva.es
 * www.gvsig.gva.es
 */

public class Main {
    /**
     * Write the bytes of "var" into new byte array.
     *
     * @param var the long of 8 bytes to encode
     * return tmp The byte array to store into.
     */
    public static void long2Arr(long var, byte[] arrayBytes, int startIndex) {

        int length = 8;

        if (arrayBytes != null && startIndex + length <= arrayBytes.length) {
            for (int j = startIndex; j < startIndex + length; j++) {
                arrayBytes[j] = (byte) var; // se copian los 8 primeros bits de la variable
                var >>= 8;
            }
        }
    }
}

Related

  1. long2array(int sz, long seed)
  2. long2buff(long n)
  3. long2char(long x)
  4. long2Date(Long date, String interval)