Java Unsigned Number Create unsignedShort2Arr(int var, byte[] arrayBytes, int startIndex)

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

Description

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

License

Open Source License

Parameter

Parameter Description
var the int that represents a unsigned short of 2 bytes to encode
arrayBytes The byte array to store into.
startIndex index data to begin write.

Declaration

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

Method Source Code

//package com.java2s;
/* DielmoOpenLiDAR//from   w w w. jav  a2  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 int that represents a unsigned short of 2 bytes to encode
     * @param arrayBytes The byte array to store into.
     * @param startIndex index data to begin write.
     */
    public static void unsignedShort2Arr(int var, byte[] arrayBytes, int startIndex) {

        int length = 2;

        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. unsignedMediumToBytes(final Long unsignedInt)
  2. unsignedNumericToByteArray(long src, int length)
  3. unsignedOneSidedGallopingIntersect2by2(final short[] smallSet, final int smallLength, final short[] largeSet, final int largeLength, final short[] buffer)
  4. unsignedShort(byte b)
  5. unsignedShort(short s)
  6. unsignedShortAt(byte[] data, int pos)
  7. unsignedShortBytesToInt(byte[] b)
  8. unsignedShortToInt(byte[] b)
  9. unsignedShortToInt(final byte[] b)