Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.text.TextUtils;

public class Main {
    public static byte[] parseHexStr2Byte(String hexStr) {
        if (TextUtils.isEmpty(hexStr)) {
            return null;
        }
        int length = hexStr.length() / 2;

        byte[] result = new byte[length];
        for (int i = 0; i < length; i++) {
            int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
            int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
            result[i] = (byte) (high * 16 + low);
        }
        return result;
    }
}