Question: Can the following snippet be successfully converted to Java?

```
u64 magic_table[5] = {
  0x1000000010000000ull,
  0x1000000000010000ull,
  0x1000000000000001ull,
  0x0100000001000000ull,
  0x0000000100000001ull
};

u64 test(u64 magic_sum, int index) {
  u64 before = magic_sum & 0x4444444444444444ull;
  u64 after = (magic_sum + magic_table[index]) & 0x4444444444444444ull;
  return after & ~before;
}

```

Answer: 
Supposing that `u64` is `uint64_t`, formally, no. Java has no
type which is capable of representing all of the values of
a `uint64_t`. Practically, it depends on what you are doing
with the values. Java *does* have a 64 bit integral type, and
if you're just looking at bits, rather than the integral value
(or if the actual values would fit in a `int64_t`), then you can
just use `long`.

The integer type suffix will just be `L`, of course, and not
`ULL`, but otherwise (for the values you give): 

```
long magicTable[] = { 
    0x1000000010000000L,
    0x1000000000010000L,
    0x1000000000000001L,
    0x0100000001000000L,
    0x0000000100000001L
};

```

should work. Java will even allow things like
`0x800000000000000L`, even though the actual value cannot be
represented in a `long`. (The resulting *value* will be
ngative.)
If you don't have time to deal with the differences in the languages(C++ vs. Java), just use [JNI](http://en.wikipedia.org/wiki/Java_Native_Interface) and you can run whatever C/C++ code in Java easily and efficiently.