Here you can find the source of convertIntToUsignedBytes(int integer)
Parameter | Description |
---|---|
integer | integer to conversion |
public static byte[] convertIntToUsignedBytes(int integer)
//package com.java2s; /*/*from w ww.ja v a 2 s . co m*/ * Collab desktop - Software for shared drawing via internet in real-time * Copyright (C) 2012 Martin Indra <aktive@seznam.cz> * * This file is part of Collab desktop. * * Collab desktop 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. * * Collab desktop 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 Collab desktop. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * converts positive or zero integer to bytes array * * @param integer integer to conversion * @return array of bytes after conversion * * @see "collab protocol documentation" */ public static byte[] convertIntToUsignedBytes(int integer) { if (integer < 0) { throw new IllegalArgumentException("Integer must be positive or zero!"); } return new byte[] { (byte) ((0xff000000 & integer) >>> 24), (byte) ((0x00ff0000 & integer) >>> 16), (byte) ((0x0000ff00 & integer) >> 8), (byte) (0x000000ff & integer) }; } }