Here you can find the source of toByteFromHexString(String hexString)
Parameter | Description |
---|---|
hexString | The hexadecimal string representing a byte |
public static byte toByteFromHexString(String hexString)
//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:/* ww w .j a v a 2 s . c om*/ * Dr.-Ing. Marc M?ltin - initial API and implementation and initial documentation *******************************************************************************/ import javax.xml.bind.DatatypeConverter; public class Main { /** * Returns a byte from a given hex string. Be careful to provide only a hex string which represents only * one byte because only the first byte of the newly created byte array will be returned. * * @param hexString The hexadecimal string representing a byte * @return One byte representing the hexadecimal string. If the hex string would represent more than * one byte, then the remaining byteArraySize-firstByte bytes are cut off. */ public static byte toByteFromHexString(String hexString) { byte[] byteArray = DatatypeConverter.parseHexBinary(hexString); return byteArray[0]; } }