Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static byte[] fromUnsigned(int[] ubytes) { if (ubytes == null) return null; byte[] res = new byte[ubytes.length]; int ubyte = 0; for (int i = 0; i < ubytes.length; i++) { ubyte = Math.abs(ubytes[i]) % 256; res[i] = (byte) (ubyte >= 128 ? ubyte - 256 : ubyte); } return res; } public static byte fromUnsigned(int singleUByte) { return (byte) (singleUByte >= 128 ? singleUByte - 256 : singleUByte); } }