Advertisement
Guest User

Trouble getting doubles from binary file

a guest
Mar 18th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1.     for (int j=0;j<3;j++){
  2.         byte testing2[] = new byte[8];
  3.         raf.read(testing2,0,8);
  4.         for(int i=0;i<8;i++){
  5.             System.out.print(testing2[i]);}
  6.         double testing2double = DataReader.bytesToDouble(testing2);
  7.         System.out.println(testing2double);
  8.                   }
  9.  
  10. //Function that is called:
  11.     public static double bytesToDouble (byte[] bytes){
  12.         byte doubles[] = new byte[8];
  13.         for(int i=7,j=0;i>-1&&j<8;i--,j++){
  14.             doubles[j]=bytes[i];}
  15.          return ByteBuffer.wrap(doubles).getDouble();
  16.         }
  17.  
  18.  /*  INPUT (from data stored in the Binary file)
  19.   *  01 00 00 9A 99 99 99 99 95 72 40 48 E1 7A 14 AE 87 37 40 9D B7 C0 03 3B
  20.   */
  21.  
  22.  /* OUTPUT (Spaces added for clarity)
  23.   *  1 0 0 -102 -103 -103 -103 -103 -2.353437370456345E-185
  24.   * -107 114 64 72 -31 122 20 -82 -1.02951151960672E-86
  25.   * -121 55 64 -99 -73 -64 3 59 2.0423918294647677E-24
  26.   */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement