de.rtner.misc
Class BinTools

java.lang.Object
  extended byde.rtner.misc.BinTools

public class BinTools
extends java.lang.Object

Free auxiliary functions. Copyright (c) 2007 Matthias Gärtner

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

For Details, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.

Version:
1.0
Author:
Matthias Gärtner

Field Summary
static java.lang.String hex
           
 
Constructor Summary
BinTools()
           
 
Method Summary
static java.lang.String bin2hex(byte[] b)
          Simple binary-to-hexadecimal conversion.
static int hex2bin(char c)
          Convert hex digit to numerical value.
static byte[] hex2bin(java.lang.String s)
          Convert hex string to array of bytes.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hex

public static final java.lang.String hex
See Also:
Constant Field Values
Constructor Detail

BinTools

public BinTools()
Method Detail

bin2hex

public static java.lang.String bin2hex(byte[] b)
Simple binary-to-hexadecimal conversion.

Parameters:
b - Input bytes. May be null.
Returns:
Hexadecimal representation of b. Uppercase A-F, two characters per byte. Empty string on null input.

hex2bin

public static byte[] hex2bin(java.lang.String s)
Convert hex string to array of bytes.

Parameters:
s - String containing hexadecimal digits. May be null. On odd length leading zero will be assumed.
Returns:
Array on bytes, non-null.
Throws:
java.lang.IllegalArgumentException - when string contains non-hex character

hex2bin

public static int hex2bin(char c)
Convert hex digit to numerical value.

Parameters:
c - 0-9, a-f, A-F allowd.
Returns:
0-15
Throws:
java.lang.IllegalArgumentException - on non-hex character

main

public static void main(java.lang.String[] args)


Copyright © 2007 Matthias Gärtner