Java Int to Byte Array intToByte2Array(int x)

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

Description

int To Byte Array

License

Open Source License

Declaration

public static byte[] intToByte2Array(int x) 

Method Source Code

//package com.java2s;
/*//from w  ww.  java 2  s. com
 * AlbatrossUtils.java
 * 
 * Copyright (C) 2008 Mark Fenton
 * 
 * 
 * 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, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static byte[] intToByte2Array(int x) {
        byte[] buf = new byte[2];
        buf[1] = (byte) ((x & 0x0000ff00) >>> 8);
        buf[0] = (byte) ((x & 0x000000ff));

        return buf;
    }
}

Related

  1. intTobyte2(int i)
  2. UIntToByte2(int value)