Friday, September 13, 2013

optmized code to represent a num in byte

    static void getByte(int n) {

        int count = 0;
        while (n >= 1) {
            arr[count++] = (byte) (n % 2);
            n = n / 2;
        }
        while (count >= 0) {
            System.out.print(arr[count--] + " ");
        }
    }

1 comment: