Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;

public class Main {
    static final byte[] HEX_CHAR_TABLE = { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5',
            (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
            (byte) 'e', (byte) 'f' };

    public static BigDecimal getNumeric(byte[] ar) throws Exception {
        BigDecimal res = new BigDecimal("0");

        String s = getHexString(ar);
        int len = s.length();
        s = s.substring(0, len - 5) + "." + s.substring(len - 5, len - 1);
        if (ar[ar.length - 1] == 13)
            s = "-" + s;

        res = new BigDecimal(s);
        return res;
    }

    public static String getHexString(byte[] raw) throws UnsupportedEncodingException {
        byte[] hex = new byte[2 * raw.length];
        int index = 0;

        for (byte b : raw) {
            int v = b & 0xFF;
            hex[index++] = HEX_CHAR_TABLE[v >>> 4];
            hex[index++] = HEX_CHAR_TABLE[v & 0xF];
        }
        return new String(hex, "ASCII");
    }
}