Java Hex Convert To fromHexString(final String s)

Here you can find the source of fromHexString(final String s)

Description

Creates byte array representation of HEX string.

License

Apache License

Parameter

Parameter Description
s string to parse

Declaration

public static byte[] fromHexString(final String s) 

Method Source Code

//package com.java2s;
/*//www .j a v  a  2  s . c o  m
 * Copyright 2009 Lukasz Wozniak 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.
 */

public class Main {
    /** Creates byte array representation of HEX string.<br>
     * 
     * @param s string to parse
     * @return */
    public static byte[] fromHexString(final String s) {
        int length = s.length() / 2;
        byte[] bytes = new byte[length];
        for (int i = 0; i < length; i++) {
            bytes[i] = (byte) (Character.digit(s.charAt(i * 2), 16) << 4 | Character
                    .digit(s.charAt(i * 2 + 1), 16));
        }
        return bytes;
    }
}

Related

  1. fromHexShort(char a)
  2. fromHexStr(final String data)
  3. fromHexString(byte abyte0[], int i)
  4. fromHexString(final String hexaString)
  5. fromHexString(final String hexString)
  6. fromHexString(final String str)
  7. fromHexString(String encoded)
  8. fromHexString(String encoded)
  9. fromHexString(String hex)