Platinum Partner

Simple Toolkit For Translation Between Byte Array And Hex String

// description of your code here


package flib.util;

import java.util.Locale;

/**
 * BD : Simple Kit for translation between byte array and hex string.
 * @author John-Lee
 */
public class HexByteKit {
    private static byte charToByte(char c){
        return (byte) "0123456789ABCDEF".indexOf(c);
    }

    /**
     * BD : Used to transfer hex string into byte array. two hex string combines one byte. So that means the length of hex string
     *      should be even. Or the null will be returned.
     * @param hexStr
     * @return
     */
    public static byte[] hex2byte(String hexStr) {
        if(hexStr == null || hexStr.isEmpty() || (hexStr.length()%2>1)) {
            return null;
        }
        String hexStrUp = hexStr.toUpperCase();
        int length = hexStrUp.length()/2;
        char[] hexChars = hexStrUp.toCharArray();
        byte[] resultByte = new byte[length];
        for(int i=0;i
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}