Here you can find the source of fromHex(String hexData)
Parameter | Description |
---|---|
hexData | hex-encoded data to decode. |
public static byte[] fromHex(String hexData)
//package com.java2s; /*//from w ww .ja v a2 s . c om * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Portions copyright 2006-2009 James Murty. Please see LICENSE.txt * for applicable license terms and NOTICE.txt for applicable notices. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ public class Main { /** * Converts a Hex-encoded data string to the original byte data. * * @param hexData * hex-encoded data to decode. * @return decoded data from the hex string. */ public static byte[] fromHex(String hexData) { byte[] result = new byte[(hexData.length() + 1) / 2]; String hexNumber = null; int stringOffset = 0; int byteOffset = 0; while (stringOffset < hexData.length()) { hexNumber = hexData.substring(stringOffset, stringOffset + 2); stringOffset += 2; result[byteOffset++] = (byte) Integer.parseInt(hexNumber, 16); } return result; } }