Java Integer to Byte Array intTo2Bytes(int x)

Here you can find the source of intTo2Bytes(int x)

Description

int To Bytes

License

Open Source License

Parameter

Parameter Description
x a parameter

Return

intTo2Bytes

Declaration

public static byte[] intTo2Bytes(int x) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013, 2015 Orange.// www .j a  v  a 2 s .c o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Victor PERRON, Antonin CHAZALET, Andre BOTTARO.
 *******************************************************************************/

public class Main {
    /**
     * @param x
     * @return intTo2Bytes
     */
    public static byte[] intTo2Bytes(int x) {
        byte[] out = new byte[2];
        out[1] = (byte) (x & 0xff);
        out[0] = (byte) ((x >> 8) & 0xff);
        return out;
    }
}

Related

  1. IntegerToBytes(int i, byte[] dst, int offset)
  2. integerToBytes(int v, byte[] b)
  3. integerToBytes(int v, byte[] b)
  4. integerToBytes(int value)
  5. integerToBytes(int x)
  6. intTo4ByteArray(int value)
  7. intTo4Bytes(int i)
  8. intToByteArray(byte[] bytes, int i)
  9. intToByteArray(final int integer)