Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static byte[] hexStringToByte(String hex) {
        int len = (hex.length() / 2);
        byte[] result = new byte[len];
        hex = hex.toLowerCase();
        int k = 0;
        for (int i = 0; i < result.length; i++) {
            byte high = (byte) (Character.digit(hex.charAt(k), 16) & 0xff);
            byte low = (byte) (Character.digit(hex.charAt(k + 1), 16) & 0xff);
            result[i] = (byte) (high << 4 | low);
            k += 2;

        }
        return result;
    }
}