Here you can find the source of intTo2Bytes(int x)
Parameter | Description |
---|---|
x | a parameter |
public static byte[] intTo2Bytes(int x)
//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; } }