java - Convert DWORD byte array to a unsigned long number -


i want unsigned value of little-endian dword byte array.

this wrote:

private long getunsignedint(byte[] data) {         long result = 0;         (int = 0; < data.length; i++) {             result += (data[i] & 0xff) << 8 * (data.length - 1 - i);         }         return result; } 

is right?

no afreaid big endian.

public long readuint(byte[] data) {     // if want tackle different lengths little endian:     //data = arrays.copyof(data, 4);     return bytebuffer.wrap(data)         .order(byteorder.little_endian)         .getint() & 0xff_ff_ff_ffl; } 

the above 4 byte (signed) int conversion , make unsigned.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -