1 19 20 package jxl.biff; 21 22 25 public class DoubleHelper 26 { 27 30 private DoubleHelper() 31 { 32 } 33 34 41 public static double getIEEEDouble(byte[] data, int pos) 42 { 43 int num1 = IntegerHelper.getInt(data[pos], data[pos + 1], 44 data[pos + 2], data[pos + 3]); 45 int num2 = IntegerHelper.getInt(data[pos + 4], data[pos + 5], 46 data[pos + 6], data[pos + 7]); 47 48 boolean negative = ((num2 & 0x80000000) != 0); 52 53 long val = ((num2 & 0x7fffffff) * 0x100000000L) + 55 (num1 < 0 ? 0x100000000L + num1 : num1); 56 double value = Double.longBitsToDouble(val); 57 58 if (negative) 59 { 60 value = -value; 61 } 62 return value; 63 } 64 65 74 public static void getIEEEBytes(double d, byte[] target, int pos) 75 { 76 long val = Double.doubleToLongBits(d); 77 target[pos] = (byte) (val & 0xff); 78 target[pos + 1] = (byte) ((val & 0xff00) >> 8); 79 target[pos + 2] = (byte) ((val & 0xff0000) >> 16); 80 target[pos + 3] = (byte) ((val & 0xff000000) >> 24); 81 target[pos + 4] = (byte) ((val & 0xff00000000L) >> 32); 82 target[pos + 5] = (byte) ((val & 0xff0000000000L) >> 40); 83 target[pos + 6] = (byte) ((val & 0xff000000000000L) >> 48); 84 target[pos + 7] = (byte) ((val & 0xff00000000000000L) >> 56) ; 85 } 86 } 87 88 89 90 | Popular Tags |