mjh mjh - 4 years ago 128
Java Question

Simple assembly code conversion to Java

I want to convert the following code into Java code. I think it is assembly code, but not sure. The part that I really do not get is

y -= m < 3;
.

int dow(int y, int m, int d)
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

Answer Source

That's C code, and I believe this

static final int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4,
  6, 2, 4 };

static int dow(int y, int m, int d) {
  if (m < 3) {
    y--;
  }
  return (y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
}

is equivalent. Because y -= m < 3; will evaluate to y-=1; if m<3 otherwise y-=0;. Instead you can use a simple if. Finally the t[] can't be static in a method in Java.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download