class BitBufferHelper {

    public static byte[] toByteArray(Number input) {
        Class<? extends Number> dataType = input.getClass();
        short size = 0;
        long longValue = input.longValue();

        if (dataType == Byte.class || dataType == byte.class) {
            size = Byte.SIZE;
        } else if (dataType == Short.class || dataType == short.class) {
            size = Short.SIZE;
        } else if (dataType == Integer.class || dataType == int.class) {
            size = Integer.SIZE;
        } else if (dataType == Long.class || dataType == long.class) {
            size = Long.SIZE;
        } else {
            throw new IllegalArgumentException("Parameter must one of the following: Short/Int/Long\n");
        }

        int length = size / NetUtils.NUM_BITS_IN_A_BYTE;
        byte[] bytes = new byte[length];

        // Getting the bytes from input value
        for (int i = 0; i < length; i++) {
            bytes[i] = (byte) (longValue >> NetUtils.NUM_BITS_IN_A_BYTE * (length - i - 1) & BYTE_MASK);
        }
        return bytes;
    }

    private  BitBufferHelper();

}