Here you can find the source of fromHexString(final String hexaString)
Parameter | Description |
---|---|
hexaString | the hexadecimal string |
public static byte[] fromHexString(final String hexaString)
//package com.java2s; /*/*from w ww.j a v a 2s . co m*/ * * JMeta - Meta's java implementation * * Copyright (C) 2013-2015 Pablo Joubert * Copyright (C) 2013-2015 Thomas Lavocat * Copyright (C) 2013-2015 Nicolas Michon * * This file is part of JMeta. * * JMeta is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * JMeta is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ public class Main { /** * Creates a ByteBuffer whose content is represented as hexadecimal in the given String. * * @param hexaString the hexadecimal string * @return the created ByteBuffer */ public static byte[] fromHexString(final String hexaString) { if ((hexaString.length() % 2) != 0) { throw new IllegalArgumentException("Input string must contain an even number of characters"); } int length = hexaString.length(); byte[] buf = new byte[length / 2]; for (int i = 0; i < length; i += 2) { buf[i / 2] = (byte) ((Character.digit(hexaString.charAt(i), 16) << 4) + Character.digit(hexaString.charAt(i + 1), 16)); } return buf; } }