C++ datatypes using this below structure ,i have to read the file.But the problem im not getting the proper values unsigned long
short
unsigned long
char[8]
char[8]
char[16]
short
short
long
long
This is the logic i am using to read unsigned long in java
private static final int bytemask = 0x0000ff;
private static final long intmask = 0x00000000ffffffffL;
long readUnsignedLong(DataInputStream in) throws IOException {
int signed = readLong(in);
long unsigned = signed & intmask;
return unsigned;
}
public int readLong(DataInputStream in) throws IOException {
int bytemask = 0x000000ff;
byte b1 = in.readByte();
byte b2 = in.readByte();
byte b3 = in.readByte();
byte b4 = in.readByte();
return makeCppSignedLong(b1, b2, b3, b4);
}
int makeCppSignedLong(byte b1, byte b2, byte b3, byte b4) {
int a1 = bytemask & b1;
int a2 = bytemask & b2;
int a3 = bytemask & b3;
int a4 = bytemask & b4;
return ((a4) << 24) + (a3 << 16) + (a2 << 8) + a1;
}