public static int[] radix(int[] a)
    {
        if (a == null)
        {
            throw new IllegalArgumentException();
        }
        if (a.length == 0)
        {
            return new int[0];
        }
        if (a.length == 1)
        {
            return new int[] { a[0] };
        }
        int d = 2;
        int w = 32;
        int partitions = w / d;
        int maskSize = 1 << d;
        int mask = maskSize - 1;
        for (int p = 0; p < partitions; ++p)
        {
            int shift = p * d;
            int[] c = new int[maskSize];
            for (int i = 0; i < a.length; ++i)
            {
                ++c[(a[i] >> shift) & mask];
            }
            for (int i = 1; i < c.length; ++i)
            {
                c[i] += c[i - 1];
            }
            int[] b = new int[a.length];
            for (int i = a.length - 1; i >= 0; --i)
            {
                b[--c[(a[i] >> shift) & mask]] = a[i];
            }
            a = b;
        }
        return a;
    }