Java Byte Array Create toByteArray(String s)

Here you can find the source of toByteArray(String s)

Description

Konvertiert einen Hex-String mit zwei Hex-Zeichen je Byte in ein Byte-Array.

License

Apache License

Declaration

public static byte[] toByteArray(String s) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * PswGen - Manages your websites and repeatably generates passwords for them
 * PswGenDroid - Generates your passwords managed by PswGen on your mobile  
 *
 *     Copyright (C) 2005-2016 Uwe Damken
 *
 * 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.//  ww  w.  ja va  2s.c  om
 *******************************************************************************/

public class Main {
    /**
     * Konvertiert einen Hex-String mit zwei Hex-Zeichen je Byte in ein Byte-Array.
     */
    public static byte[] toByteArray(String s) {
        byte[] ba = new byte[s.length() / 2];
        for (int i = 0; i < ba.length; i++) {
            ba[i] = toByte(s.substring(2 * i, 2 * i + 2));
        }
        return ba;
    }

    public static byte toByte(String s) {
        return (Integer.valueOf(Integer.parseInt(s, 16))).byteValue();
    }
}

Related

  1. toByteArray(String hexStr)
  2. toByteArray(String hexString)
  3. toByteArray(String hexString)
  4. toByteArray(String hexString)
  5. toByteArray(String map)
  6. toByteArray(String source)
  7. toByteArray(String str)
  8. toByteArray(String str)
  9. toByteArray(String str)