Here you can find the source of convertHexStringToBytes(String hex)
Parameter | Description |
---|---|
hex | The hexadecimal String to be converted into an array of bytes. |
public static byte[] convertHexStringToBytes(String hex)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**// w w w .j a va2 s . c om * Converts a hexadecimal String (such as one generated by the * {@link #convertBytesToHexString(byte[])} method) into an array of bytes. * @param hex The hexadecimal String to be converted into an array of bytes. * @return An array of bytes that. */ public static byte[] convertHexStringToBytes(String hex) { if (hex.length() % 2 != 0) { throw new IllegalArgumentException("Hex string must have even number of characters."); } byte[] seed = new byte[hex.length() / 2]; for (int i = 0; i < seed.length; i++) { int index = i * 2; seed[i] = (byte) Integer.parseInt(hex.substring(index, index + 2), 16); } return seed; } }