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 ConvertStringToHexByte(String StringToConvert) {
        StringToConvert = StringToConvert.toUpperCase();
        char[] CharArray = StringToConvert.toCharArray();
        char[] Char = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        int result = 0;
        for (int i = 0; i <= 1; i++) {
            for (int j = 0; j <= 15; j++) {
                if (CharArray[i] == Char[j]) {
                    if (i == 1) {
                        result = result + j;
                        j = 15;
                    }

                    else if (i == 0) {
                        result = result + j * 16;
                        j = 15;
                    }
                }
            }
        }
        return (byte) result;
    }
}