package org.lichess.clockencoder;

public class LowBitTruncator {
    // Truncate 3 bits from centisecs, but preserve precision for low values.
    // CENTI_CUTOFF must be a multiple of 8 (the truncation divisor)
    private static final int CENTI_CUTOFF = 2000;

    public static void truncate(int[] centis) {
        int moves = centis.length;
        for (int i = 0; i < moves; i++) {
            centis[i] >>= 3;
        }
    }

    public static int truncate(int centi) {
        return centi >> 3;
    }

    public static void writeDigits(int[] centis, BitWriter writer) {
        int maxIdx = centis.length - 1;
        for (int i = 0; i <= maxIdx; i++) {
            // Always store full precision end.
            if (centis[i] < CENTI_CUTOFF || i == maxIdx)
                writer.writeBits(centis[i], 3);
        }
    }

    public static void decode(int[] trunced, BitReader reader) {
        int maxIdx = trunced.length - 1;
        for (int i = 0; i <= maxIdx; i++) {
            int rounded = trunced[i] << 3;
            if (rounded < CENTI_CUTOFF || i == maxIdx) {
                trunced[i] = rounded | reader.readBits(3);
            } else {
                // Truncation cuts off 3.5 on average.
                trunced[i] = rounded | 3;
            }
        }
    }
}

@@ -634,33 +634,32 @@
  (int i = 0; i %3C
-=
  maxIdx; i++) %7B%0A
@@ -662,56 +662,8 @@
 ) %7B%0A
-            // Always store full precision end.%0A
     
@@ -698,31 +698,17 @@
 I_CUTOFF
- %7C%7C i == maxIdx
+)
 )%0A      
@@ -751,32 +751,121 @@
 , 3);%0A        %7D%0A
+        // Always store full precision end.%0A        writer.writeBits(centis%5BmaxIdx%5D, 3);%0A
     %7D%0A%0A    publi

Update LowBitTruncator.java