Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String HEX_CHARACTERS = "0123456789ABCDEF";

    public static int hex2dec(String hexValue) {
        hexValue = hexValue.toUpperCase();
        int decimalResult = 0;

        for (int i = 0; i < hexValue.length(); i++) {
            char digit = hexValue.charAt(i);
            int digitValue = HEX_CHARACTERS.indexOf(digit);
            decimalResult = decimalResult * 16 + digitValue;
        }
        return decimalResult;
    }
}