Android Int to Byte Array Convert IntToBytes(int value)

Here you can find the source of IntToBytes(int value)

Description

Int To Bytes

License

Open Source License

Declaration

public static byte[] IntToBytes(int value) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2010-2011 Dmitriy Nesterov
 *
 * 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 3 of the License, or
 * (at your option) any later version./*www .  j a  v  a2s  . c om*/
 *
 * 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[] IntToBytes(int value) {
        byte[] result = new byte[4];
        result[0] = (byte) (value >> 24);
        result[1] = (byte) ((value << 8) >> 24);
        result[2] = (byte) ((value << 16) >> 24);
        result[3] = (byte) ((value << 24) >> 24);

        return result;
    }
}

Related

  1. intToBytes(byte[] bytes, int offset, int value)
  2. intToBytes(int number)
  3. intToBytes(int number)
  4. toByteArray(int in)