Hi there,
I have a buffer of 4 bytes long. These four bytes together store a hex value of file size. The code below was written is C and it works.
char *ptr;
unsigned long fileSize = (( unsigned char ) * (ptr+24) * 256 * 256 * 256 ) +
(( unsigned char ) * (ptr+23) * 256 * 256 ) +
(( unsigned char ) * (ptr+22) * 256 ) +
( unsigned char ) *( ptr+21);
Now, I rewrite this section of code in
Java, but I don't get the correct result. I think the issue java does not has unsigned char. Any input is appreciated. Thank you very much.
public int getFileSize(int offset)
{
byte[] buffer = //reading from InputStream
long fileSizeL;
byte byte24 = buffer[offset + 24];
byte byte23 = buffer[offset + 23];
byte byte22 = buffer[offset + 22];
byte byte21 = buffer[offset + 21];
fileSizeL = (byte24) * (long)(256 * 256 * 256) +
(byte23) * (long)(256 * 256) +
(byte22) * 256 +
(byte21);
return fileSizeL;
}