Java XML Hex toByteFromHexString(String hexString)

Here you can find the source of toByteFromHexString(String hexString)

Description

Returns a byte from a given hex string.

License

Open Source License

Parameter

Parameter Description
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.

Declaration

public static byte toByteFromHexString(String hexString) 

Method Source Code

//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];
    }
}

Related

  1. sha1Hex(String message)
  2. stringToHex(String str)
  3. toByteArray(String hex)
  4. toByteArray(String hexDumpString)
  5. toByteArrayFromHexString(String s)
  6. toHex(byte[] bytes)
  7. toHex(byte[] bytes)
  8. toHex(byte[] donnees)
  9. toHex(String str)