Avril Lavigne - 1 year ago 55

Java Question

This is an algorithm in Java and I need to understand it to implement it in javascript.

`//cc=array[4] a=array[512] n=a.lenght`

ncof = cc.length;

ioff = joff = -(ncof >> 1);

ouptput = new double[n];

int nmod = ncof * n;

int n1 = n - 1;

int nh = n >> 1;

for (int ii = 0, i = 0; i < n; i += 2, ii++) {

int ni = i + 1 + nmod + ioff;

int nj = i + 1 + nmod + joff;

for (int k = 0; k < ncof; k++) {

int jf = n1 & (ni + k + 1);

int jr = n1 & (nj + k + 1);

ouptput[ii] += cc[k] * a[jf];

ouptput[ii + nh] += cr[k] * a[jr];

}

}

this is what I have done so far:

`function foo(a, cc){`

ncof = cc.length;

ioff = joff = -1 * (ncof / 2);

op = Array(n);

nmod = ncof * n;

n1 = n - 1;

nh = n / 2;

for (int ii = 0, i = 0; i < n; i += 2, ii++) {

ni = i + 1 + nmod + ioff;

nj = i + 1 + nmod + joff;

for (int k = 0; k < ncof; k++) {

//jf = n1 & (ni + k + 1); // What is this??????

//jr = n1 & (nj + k + 1);

ouptput[ii] += cc[k] * a[jf];

ouptput[ii + nh] += cr[k] * a[jr];

}

}

}

what does

`int jf = n1 & (ni + k + 1);`

also tell me if Ive made a mistake so far.

Answer Source

The part that you asked :

```
int jf = n1 & (ni + k + 1)
```

is something like this:

```
int var1 = ni + k + 1;
int jf = n1&var1;
```

& is a bitwise operator in Java:

Something like this taken from http://www.tutorialspoint.com/java/java_basic_operators.htm:

Bitwise operator works on bits and performs bit-by-bit operation. Assume if a = 60; and b = 13; now in binary format they will be as follows:

`a = 0011 1100 b = 0000 1101 ----------------- a&b = 0000 1100 a|b = 0011 1101`

For more on bitwise operators read here.