Hi everyone,
I have a program that converts variables long,string,dou ble to byte array here's the code :
for long :
for String :
for double :
Now the problem is i don't know how to convert it back. Byte array back to its
different datatypes (long, String, double).
any help will be appreciated,
Regards,
Jeff
I have a program that converts variables long,string,dou ble to byte array here's the code :
for long :
Code:
//CompanyId
temp = longToByteArray(CompanyId);
for (i=0,i2=7; i<5; i++,i2--)
buffer[position + i] = temp[i2];
private byte[] longToByteArray(long l)
{
byte[] bArray = new byte[8];
ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
LongBuffer lBuffer = bBuffer.asLongBuffer();
lBuffer.put(0, l);
return bArray;
}
Code:
//CustomerCode
for (i=0; i <20; i++)
{
if (i < customerCode.length())
buffer[i + position] = (byte) customerCode.charAt(i);
else
buffer[i + position] = 0;
}
Code:
// LastClaimPoints
temp = longToByteArray( Double.doubleToRawLongBits(LastClaimPoints));
for (i=0; i<8; i++)
buffer[position+i] = temp[i];
private byte[] longToByteArray(long l)
{
byte[] bArray = new byte[8];
ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
LongBuffer lBuffer = bBuffer.asLongBuffer();
lBuffer.put(0, l);
return bArray;
}
Now the problem is i don't know how to convert it back. Byte array back to its
different datatypes (long, String, double).
any help will be appreciated,
Regards,
Jeff
Comment