G
GeniousFayaz
Hi,
I am new to java and I have troubles with doubles. I have 8 bytes and
I need to convert them to a single double. I searched the net and
found out this piece of code
(with all respect to the Author and his rights)
<code>
public static double arr2double(byte[] arr, int start) {
int i = 0;
int len = 8;
int cnt = 0;
byte[] tmp = new byte[len];
for (i = start; i < (start + len); i++) {
tmp[cnt] = arr;
//System.out.println(java.lang.Byte.toString(arr) + " "
+ i);
cnt++;
}
long accum = 0;
i = 0;
for ( int shiftBy = 0; shiftBy < 64; shiftBy += 8 ) {
accum |= ( (long)( tmp & 0xff ) ) << shiftBy;
i++;
}
</code>
but when I gave the following array
<code>
byte[] byteArray = new byte[]{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1};
</code>
instead of returning the value 1 (one) the above method returned me
some other
value. I even tried going through IEEE 754 standards but they were
absolutely
out of my scope.
Can any one guide me in "How to convert the given byte array into a
double value" ?
Thanks in advance for all Ur efforts
-F
I am new to java and I have troubles with doubles. I have 8 bytes and
I need to convert them to a single double. I searched the net and
found out this piece of code
(with all respect to the Author and his rights)
<code>
public static double arr2double(byte[] arr, int start) {
int i = 0;
int len = 8;
int cnt = 0;
byte[] tmp = new byte[len];
for (i = start; i < (start + len); i++) {
tmp[cnt] = arr;
//System.out.println(java.lang.Byte.toString(arr) + " "
+ i);
cnt++;
}
long accum = 0;
i = 0;
for ( int shiftBy = 0; shiftBy < 64; shiftBy += 8 ) {
accum |= ( (long)( tmp & 0xff ) ) << shiftBy;
i++;
}
</code>
but when I gave the following array
<code>
byte[] byteArray = new byte[]{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1};
</code>
instead of returning the value 1 (one) the above method returned me
some other
value. I even tried going through IEEE 754 standards but they were
absolutely
out of my scope.
Can any one guide me in "How to convert the given byte array into a
double value" ?
Thanks in advance for all Ur efforts
-F