Here you can find the source of convertStringToByte(String strValue)
Parameter | Description |
---|---|
strValue | a parameter |
protected static byte convertStringToByte(String strValue)
//package com.java2s; /* $Revision: 159 $ $Date: 2009-08-17 12:52:56 +0000 (ma, 17 aug 2009) $ $Author: blohman $ * /*from ww w . ja v a2 s .com*/ * Copyright (C) 2007-2009 National Library of the Netherlands, * Nationaal Archief of the Netherlands, * Planets * KEEP * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * For more information about this project, visit * http://dioscuri.sourceforge.net/ * or contact us via email: * jrvanderhoeven at users.sourceforge.net * blohman at users.sourceforge.net * bkiers at users.sourceforge.net * * Developed by: * Nationaal Archief <www.nationaalarchief.nl> * Koninklijke Bibliotheek <www.kb.nl> * Tessella Support Services plc <www.tessella.com> * Planets <www.planets-project.eu> * KEEP <www.keep-project.eu> * * Project Title: DIOSCURI */ public class Main { /** * Converts a given string into a byte of one integer * * @param strValue * @return int as byte */ protected static byte convertStringToByte(String strValue) { // FIXME: Check if correct byte implementation // Parse from string to int (hex) try { byte intRegVal = 0; for (int i = strValue.length(); i > 0; i--) { intRegVal = (byte) (intRegVal + ((int) Math.pow(16, strValue.length() - i)) * Integer.parseInt(strValue.substring(i - 1, i), 16)); } return intRegVal; } catch (NumberFormatException e) { return -1; } } }