Here you can find the source of toByteArrayFromHexString(String s)
Parameter | Description |
---|---|
hexString | The hexadecimal string representing a byte array. The lexical value space defined in XML Schema Part 2: Datatypes for xsd:hexBinary is expected: "hexBinary has a lexical representation where each binary octet is encoded as a character tuple, consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code. For example, '0FB7' is a hex encoding for the 16-bit integer 4023 (whose binary representation is 111110110111)." |
public static byte[] toByteArrayFromHexString(String s)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Dr.-Ing. Marc M?ltin. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from ww w .j a v a 2 s. c o m*/ * Dr.-Ing. Marc M?ltin - initial API and implementation and initial documentation *******************************************************************************/ import javax.xml.bind.DatatypeConverter; public class Main { /** * Returns a byte array from a given hex string. * * @param hexString The hexadecimal string representing a byte array. The lexical value space * defined in XML Schema Part 2: Datatypes for xsd:hexBinary is expected: * "hexBinary has a lexical representation where each binary octet is encoded * as a character tuple, consisting of two hexadecimal digits ([0-9a-fA-F]) * representing the octet code. For example, '0FB7' is a hex encoding for the * 16-bit integer 4023 (whose binary representation is 111110110111)." * @return A byte array representing the hexadecimal string */ public static byte[] toByteArrayFromHexString(String s) { return DatatypeConverter.parseHexBinary(s); } }