public static byte[] hexStringToByteArray(String input) {
        String cleanInput = cleanHexPrefix(input);

        int len = cleanInput.length();

        if (len == 0) {
            return new byte[] {};
        }

        byte[] data;
        int startIdx;
        if (len % 2 != 0) {
            data = new byte[(len / 2) + 1];
            data[0] = (byte) Character.digit(cleanInput.charAt(0), 16);
            startIdx = 1;
        } else {
            data = new byte[len / 2];
            startIdx = 0;
        }

        for (int i = startIdx; i < len; i += 2) {
            data[(i + 1) / 2] =
                    (byte)
                            ((Character.digit(cleanInput.charAt(i), 16) << 4)
                                    + Character.digit(cleanInput.charAt(i + 1), 16));
        }
        return data;
    }
@Test
    public void testHexStringToByteArray() {
        assertArrayEquals(Numeric.hexStringToByteArray(""), (new byte[] {}));
        assertArrayEquals(Numeric.hexStringToByteArray("0"), (new byte[] {0}));
        assertArrayEquals(Numeric.hexStringToByteArray("1"), (new byte[] {0x1}));
        assertArrayEquals(Numeric.hexStringToByteArray(HEX_RANGE_STRING), (HEX_RANGE_ARRAY));

        assertArrayEquals(Numeric.hexStringToByteArray("0x123"), (new byte[] {0x1, 0x23}));
    }