Java Bits Convert to bitsCleanup(int base, int[] bits)

Here you can find the source of bitsCleanup(int base, int[] bits)

Description

bits Cleanup

License

Open Source License

Declaration

public static int[] bitsCleanup(int base, int[] bits) 

Method Source Code

//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);
    }
}

Related

  1. bitrv2conj(int n, int[] ip, double[] a, int offa)
  2. bits2float(int i)
  3. bits2Numeric(boolean[] in)
  4. bitsArrayToByte(byte[] bits)
  5. bitscanForward(long bitboard)
  6. BitsNeeded(int n)
  7. bitsRequired(double minValue, double maxValue)
  8. bitsRequired(int value)
  9. bitsRequiredForFraction(String floatnumber)