Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] hexStringToByte(String aMessage) {
        int i = aMessage.length() / 2;
        byte[] arrayOfByte = new byte[i];
        char[] arrayOfChar = aMessage.toCharArray();
        for (int j = 0; j < i; j++) {
            int k = j * 2;
            arrayOfByte[j] = ((byte) (toByte(arrayOfChar[k]) << 4 | toByte(arrayOfChar[(k + 1)])));
        }
        return arrayOfByte;
    }

    public static byte toByte(char paramChar) {
        return (byte) "0123456789ABCDEF".indexOf(paramChar);
    }
}