DataConversion.java

Go to the documentation of this file.
00001 package theba.core.io;
00002 
00009 public class DataConversion {
00010         static byte[] output;
00011 
00012         public static byte[] shortToBytes(short[] arr) {
00013                 if (output == null || output.length != arr.length * 2)
00014                         output = new byte[arr.length * 2];
00015                 for (int i = 0; i < arr.length; i++) {
00016                         output[i * 2] = (byte) (arr[i] & 0xff);
00017                         output[i * 2 + 1] = (byte) ((arr[i] >> 8) & 0xff);
00018                 }
00019                 return output;
00020         }
00021 
00034         public static short bytesToShort(byte[] byteArray, int offset) {
00035                 short result = (short) ((byteArray[offset++] << 8) | (0x000000FF & byteArray[offset]));
00036                 return result;
00037         }
00038 
00039 }

Generated on Fri Nov 13 08:57:07 2009 for Theba by  doxygen 1.6.1