public int decodeVarBits() throws IOException {
        fillBuffer();
        final int b12 = b & 0xfff;
        final int len = vl_length[b12];
        if (len <= 12) {
            b >>>= len;
            bits -= len;
            return vl_values[b12]; // full value lookup
        }
        if (len <= 23) { // // only length lookup
            final int len2 = len >> 1;
            b >>>= len2 + 1;
            int mask = 0xffffffff >>> (32 - len2);
            mask += b & mask;
            b >>>= len2;
            bits -= len;
            return mask;
        }
        if ((b & 0xffffff) != 0) {
            // here we just know len in [25..47]
            // ( fillBuffer guarantees only 24 bits! )
            b >>>= 12;
            final int len3 = 1 + (vl_length[b & 0xfff] >> 1);
            b >>>= len3;
            final int len2 = 11 + len3;
            bits -= len2 + 1;
            fillBuffer();
            int mask = 0xffffffff >>> (32 - len2);
            mask += b & mask;
            b >>>= len2;
            bits -= len2;
            return mask;
        }
        return decodeVarBits2(); // no chance, use the slow one
    }
decode an integer in the range 0..max (inclusive).
main/src/main/java/cgeo/geocaching/brouter/util/MixCoderDataInputStream.java