byte array to decimal convertion in java

前端 未结 4 1046
傲寒
傲寒 2020-12-22 03:59

I am new to java. I receive the UDP data in byte array. Each elements of the byte array have the hexadecimal value. I need to convert each element to integer.

How to

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-22 04:48

    sample code:

     public int[] bytearray2intarray(byte[] barray)
     {
       int[] iarray = new int[barray.length];
       int i = 0;
       for (byte b : barray)
           iarray[i++] = b & 0xff;
       // "and" with 0xff since bytes are signed in java
       return iarray;
     }
    

提交回复
热议问题