欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java转换字节数组(byte array)为整形(int),bytearray,/** * Conver

来源: javaer 分享于  点击 8311 次 点评:7

Java转换字节数组(byte array)为整形(int),bytearray,/** * Conver


/** * Convert the byte array to an int. * * @param b The byte array * @return The integer */public static int byteArrayToInt(byte[] b) {    return byteArrayToInt(b, 0);}/** * Convert the byte array to an int starting from the given offset. * * @param b The byte array * @param offset The array offset * @return The integer */public static int byteArrayToInt(byte[] b, int offset) {    int value = 0;    for (int i = 0; i < 4; i++) {        int shift = (4 - 1 - i) * 8;        value += (b[i + offset] & 0x000000FF) << shift;    }    return value;}
相关栏目:

用户点评