Here you can find the source of fromHexString(final String s)
Parameter | Description |
---|---|
s | string to parse |
public static byte[] fromHexString(final String s)
//package com.java2s; /*//www .j a v a 2 s . c o m * Copyright 2009 Lukasz Wozniak Licensed under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law * or agreed to in writing, software distributed under the License 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 { /** Creates byte array representation of HEX string.<br> * * @param s string to parse * @return */ public static byte[] fromHexString(final String s) { int length = s.length() / 2; byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { bytes[i] = (byte) (Character.digit(s.charAt(i * 2), 16) << 4 | Character .digit(s.charAt(i * 2 + 1), 16)); } return bytes; } }