Here you can find the source of byteArrayFromHexString(String in)
Parameter | Description |
---|---|
in | a hexadecimal string |
public static byte[] byteArrayFromHexString(String in)
//package com.java2s; /****************************************************************************** * * Copyright (c) 2005-2011 Cryptzone Group AB. All Rights Reserved. * // ww w .jav a2 s . c o m * This file contains Original Code and/or Modifications of Original Code as * defined in and that are subject to the MindTerm Public Source License, * Version 2.0, (the 'License'). You may not use this file except in compliance * with the License. * * You should have received a copy of the MindTerm Public Source License * along with this software; see the file LICENSE. If not, write to * Cryptzone Group AB, Drakegatan 7, SE-41250 Goteborg, SWEDEN * *****************************************************************************/ public class Main { /** * Convert an hex-string to byte array "0001a0" -> {0x00, 0x01, 0xa0} * * @param in a hexadecimal string * @return a byte array */ public static byte[] byteArrayFromHexString(String in) { byte out[] = new byte[in.length() / 2]; for (int i = 0; i < in.length(); i += 2) { out[i / 2] = (byte) Integer.parseInt(in.substring(i, i + 2), 16); } return out; } }