List of usage examples for java.lang Integer reverse
public static int reverse(int i)
From source file:Main.java
public static void main(String[] args) { System.out.println(Integer.reverse(10)); }
From source file:com.t_oster.liblasercut.drivers.LaosCutter.java
/** * This Method takes a raster-line represented by a list of bytes, * where: byte0 ist the left-most byte, in one byte, the MSB is the * left-most bit, 0 representing laser off, 1 representing laser on. * The Output List of longs, where each value is the unsigned dword * of 4 bytes of the input each, where the first dword is the leftmost * dword and the LSB is the leftmost bit. If outputLeftToRight is false, * the first dword is the rightmost dword and the LSB of each dword is the * the Output is padded with zeroes on the right side, if leftToRight is true, * on the left-side otherwise// ww w . ja v a2 s .com * rightmost bit * @param line * @param outputLeftToRight * @return */ public List<Long> byteLineToDwords(List<Byte> line, boolean outputLeftToRight) { List<Long> result = new ArrayList<Long>(); int s = line.size(); for (int i = 0; i < s; i++) { line.set(i, (byte) (Integer.reverse(0xFF & line.get(i)) >>> 24)); } for (int i = 0; i < s; i += 4) { result.add((((long) (i + 3 < s ? 0xFF & line.get(i + 3) : 0)) << 24) + (((long) (i + 2 < s ? 0xFF & line.get(i + 2) : 0)) << 16) + (((long) (i + 1 < s ? 0xFF & line.get(i + 1) : 0)) << 8) + ((long) (0xFF & line.get(i)))); } if (!outputLeftToRight) { Collections.reverse(result); for (int i = 0; i < result.size(); i++) { result.set(i, Long.reverse(result.get(i)) >>> 32); } } return result; }
From source file:org.briljantframework.math.transform.DiscreteFourierTransform.java
private static void transformRadix2(ComplexArray a) { final int n = a.size(); int levels = (int) Math.floor(Math.log(n) / Math.log(2)); if (1 << levels != n) { throw new IllegalArgumentException(); }//from w w w . j a v a 2 s . co m DoubleArray cosTable = DoubleArray.zeros(n / 2); DoubleArray sinTable = DoubleArray.zeros(n / 2); final double v = 2 * Math.PI; for (int i = 0; i < n / 2; i++) { cosTable.set(i, Math.cos(v * i / n)); sinTable.set(i, Math.sin(v * i / n)); } // Bit-reversed addressing permutation (i.e. even addresses in the first half and odd in the // second half) for (int i = 0; i < n; i++) { int j = Integer.reverse(i) >>> (32 - levels); if (j > i) { a.swap(j, i); } } // Cooley-Tukey decimation-in-time radix-2 FFT for (int size = 2; size <= n; size *= 2) { int halfSize = size / 2; int tableStep = n / size; for (int i = 0; i < n; i += size) { for (int j = i, k = 0; j < i + halfSize; j++, k += tableStep) { Complex hjVal = a.get(j + halfSize); Complex jVal = a.get(j); double cos = cosTable.get(k); double sin = sinTable.get(k); double tpre = hjVal.getReal() * cos + hjVal.getImaginary() * sin; double tpim = -hjVal.getReal() * sin + hjVal.getImaginary() * cos; a.set(j + halfSize, new Complex(jVal.getReal() - tpre, jVal.getImaginary() - tpim)); a.set(j, new Complex(jVal.getReal() + tpre, jVal.getImaginary() + tpim)); } } if (size == n) { break; } } }