daniel-s
6/7/2014 - 10:25 AM

Convert an unsigned integer to signed (keeping binary value).

Convert an unsigned integer to signed (keeping binary value).

/**
	 * Convert an unsigned integer to signed (keeping binary value)
	 * 
	 * @param binary Integer whose binary value need to convert
	 * @return A byte with same binary than income integer
	 */
	private static byte fromBinaryToByte(int binary)
	{
		byte result = -1;

		String s = Integer.toBinaryString(binary);

		result = (byte) Integer.parseInt(s, 2);

		return result;
	}