Here you can find the source of bitsCleanup(int base, int[] bits)
public static int[] bitsCleanup(int base, int[] bits)
//package com.java2s; //License from project: Open Source License public class Main { public static int[] bitsCleanup(int base, int[] bits) { int i = 0; if (isNegative(base, bits)) { for (; i < bits.length && bits[bits.length - i - 1] == base - 1; i++) ;// w w w. ja v a 2 s.co m } else { for (; i < bits.length && bits[bits.length - i - 1] == 0; i++) ; } if (i > 0) { int[] clean = new int[bits.length - i + 1]; System.arraycopy(bits, 0, clean, 0, clean.length); return clean; } else { return bits; } } public static boolean isNegative(int base, int[] bits) { return (bits.length != 0 && bits[bits.length - 1] >= base / 2); } }