Convert an array of 16.16 fixed-point values to floating point : Array « Date Type « Android






Convert an array of 16.16 fixed-point values to floating point

  
//package edu.dhbw.andobjviewer.util;

// Much of this is adapted from the beartronics FP lib
 class FixedPointUtils {
  public static final int ONE = 0x10000;

  /**
   * Convert an array of floats to 16.16 fixed-point
   * @param arr The array
   * @return A newly allocated array of fixed-point values.
   */
  public static int[] toFixed(float[] arr) {
    int[] res = new int[arr.length];
    toFixed(arr, res);
    return res;
  }
  
  /**
   * Convert a float to  16.16 fixed-point representation
   * @param val The value to convert
   * @return The resulting fixed-point representation
   */
  public static int toFixed(float val) {
    return (int)(val * 65536F);
  }

  /**
   * Convert an array of floats to 16.16 fixed-point
   * @param arr The array of floats
   * @param storage The location to store the fixed-point values.
   */
  public static void toFixed(float[] arr, int[] storage)
  {
    for (int i=0;i<storage.length;i++) {
      storage[i] = toFixed(arr[i]);
    }
  }
  
  /**
   * Convert a 16.16 fixed-point value to floating point
   * @param val The fixed-point value
   * @return The equivalent floating-point value.
   */
  public static float toFloat(int val) {
    return ((float)val)/65536.0f;
  }
  
  /**
   * Convert an array of 16.16 fixed-point values to floating point
   * @param arr The array to convert
   * @return A newly allocated array of floats.
   */
  public static float[] toFloat(int[] arr) {
    float[] res = new float[arr.length];
    toFloat(arr, res);
    return res;
  }
  
  /**
   * Convert an array of 16.16 fixed-point values to floating point
   * @param arr The array to convert
   * @param storage Pre-allocated storage for the result.
   */
  public static void toFloat(int[] arr, float[] storage)
  {
    for (int i=0;i<storage.length;i++) {
      storage[i] = toFloat(arr[i]);
    }
  }
  
}

   
    
  








Related examples in the same category

1.Load string array value from strings.xml
2.Returns a clone of the specified array.
3.Tests two arrays for equality.
4.Transforms a list of Float values into an array of float.
5.Split the string into an array of strings using one of the separator in 'sep'.
6.Int array to HashSet
7.Array Iterator
8.Convert an array of floats to 16.16 fixed-point
9.Reverse an array
10.Using android.util.SparseArray
11.Join an array of Strings together.
12.Compare Arrays
13.Does Array contain a certain item
14.Create Array with Unique Value
15.Resize a Java array
16.Get Node value and save to ArrayList
17.read the photo file into a byte array
18.byte Array To Int
19.load 16 Bit PCM Raw Data File As Double Array
20.convert From Short Array To Double Array
21.convert From Double Array To Short Array
22.get Set From Array
23.Convert an array of floats to 16.16 fixed-point 2
24.int To Byte Array 4
25.Convert a byte array to a boolean array. Bit 0 is represented with false, Bit 1 is represented with 1
26.Return a subarray of the byte array in parameter.