Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {

    public static int getDataLength(byte byte1, byte byte2) {
        int len16 = 0;
        String hex = Integer.toHexString(byte1 & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }
        len16 = Integer.valueOf(hex, 16);
        int len17 = 0;
        String hex1 = Integer.toHexString(byte2 & 0xFF);
        if (hex1.length() == 1) {
            hex1 = '0' + hex1;
        }
        len17 = Integer.valueOf(hex1, 16);
        int pktLen = len16 * 256 + len17;
        return pktLen;
    }

    public static String toHexString(byte[] b) {
        StringBuffer buffer = new StringBuffer();
        if (b != null)
            for (int i = 0; i < b.length; ++i) {
                String s = Integer.toHexString(b[i] & 0xFF);
                if (s.length() == 1) {
                    s = "0" + s;
                }
                buffer.append(s + " ");
            }
        return buffer.toString();
    }
}