in src/main/java/com/uber/h3core/H3Core.java [715:734]
public long cellToParent(long h3, int res) {
// This is a ported version of h3ToParent from h3core.
int childRes = (int) ((h3 & H3_RES_MASK) >> H3_RES_OFFSET);
if (res < 0 || res > childRes) {
throw new IllegalArgumentException(
String.format("res (%d) must be between 0 and %d, inclusive", res, childRes));
} else if (res == childRes) {
return h3;
}
// newRes is the bits that need to be set to set the given resolution.
long newRes = (long) res << H3_RES_OFFSET;
long digitMaskForRes = H3_DIGIT_MASK;
for (int i = 0; i < res; i++) {
digitMaskForRes >>= 3L;
}
return (h3 & H3_RES_MASK_NEGATIVE) | newRes | digitMaskForRes;
}