Here you can find the source of toByteArrayFromString(String value, int radix)
public static byte[] toByteArrayFromString(String value, int radix)
//package com.java2s; /*/*from w w w . j ava2s .co m*/ // Licensed to DynamoBI Corporation (DynamoBI) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. DynamoBI licenses this file // to you 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 { /** * Converts a string into a byte array. The inverse of {@link * #toStringFromByteArray(byte[], int)}. */ public static byte[] toByteArrayFromString(String value, int radix) { assert 16 == radix : "Specified string to byte array conversion not supported yet"; assert (value.length() % 2) == 0 : "Hex binary string must contain even number of characters"; byte[] ret = new byte[value.length() / 2]; for (int i = 0; i < ret.length; i++) { int digit1 = Character.digit(value.charAt(i * 2), radix); int digit2 = Character.digit(value.charAt((i * 2) + 1), radix); assert (digit1 != -1) && (digit2 != -1) : "String could not be converted to byte array"; ret[i] = (byte) ((digit1 * radix) + digit2); } return ret; } }