package com.coding.mini_jvm.src.com.coderising.jvm.util; public class Util { public static int byteToInt(byte[] codes){ String s1 = byteToHexString(codes); return Integer.valueOf(s1, 16).intValue(); } public static int bytes2Int(byte[] b, int start, int len) { int sum = 0; int end = start + len; for (int i = start; i < end; i++) { int n = ((int) b[i]) & 0xff; n <<= (--len) * 8; sum = n + sum; } return sum; } public static String byte2String(byte[] b, int start, int len) { return new String(b, start, len); } public static String byteToHexString(byte[] codes ){ StringBuffer buffer = new StringBuffer(); for(int i=0;i<codes.length;i++){ byte b = codes[i]; int value = b & 0xFF; String strHex = Integer.toHexString(value); if(strHex.length()< 2){ strHex = "0" + strHex; } buffer.append(strHex); } return buffer.toString(); } }