private static long codeToId(final String expectedPraefix, final String code, final boolean ignoreWrongCodes) {
        if (StringUtils.isBlank(code) || code.length() < expectedPraefix.length() + 1 || !code.startsWith(expectedPraefix)) {
            return 0;
        }
        long base = GC_BASE31;
        final String geocodeWO = code.substring(expectedPraefix.length()).toUpperCase(Locale.US);

        if (geocodeWO.length() < 4 || (geocodeWO.length() == 4 && indexOfGcIdSeq(geocodeWO.charAt(0)) < 16)) {
            base = GC_BASE16;
        }

        long gcid = 0;
        for (int p = 0; p < geocodeWO.length(); p++) {
            final int idx = indexOfGcIdSeq(geocodeWO.charAt(p));
            if (idx < 0 && !ignoreWrongCodes) {
                //idx < 0 means that there's an invalid char in given code
                return 0;
            }
            gcid = base * gcid + idx;
        }

        if (base == GC_BASE31) {
            gcid += Math.pow(16, 4) - 16 * Math.pow(31, 3);
        }
        return gcid;
    }
Converts logId to LogCode. For invalid id's, empty string will be returned (never null)
main/src/main/java/cgeo/geocaching/connector/gc/GCUtils.java