daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Apr 20th, 2013 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     // we assume that each entry in data[] is an int in [0,127]
  3.     public byte[] getByteArrayRepresentation() {
  4.         byte[] result = new byte[data.length/2];
  5.         for (int i = 0; i < result.length; i++) {
  6.             tmp = ((int) (data[(i << 1)] * 2)) << 4;
  7.             tmp = (tmp | ((int) (data[(i << 1) + 1] * 2)));
  8.             result[i] = (byte) (tmp-128);
  9.         }
  10.         return result;
  11.     }    
  12.  
  13.     public void setByteArrayRepresentation(byte[] in) {
  14.         for (int i = 0; i < in.length; i++) {
  15.             tmp = in[i]+128;
  16.             data[(i << 1) +1] = ((double) (tmp & 0x000F))/2d;
  17.             data[i << 1] = ((double) (tmp >> 4))/2d;
  18.         }
  19.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand