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 getMacAddr(byte[] data) {
        if (data != null && data.length > 11) {
            byte[] macBytes = new byte[6];
            System.arraycopy(data, 5, macBytes, 0, 6);
            return byteToMac(macBytes);
        }
        return null;
    }

    public static String byteToMac(byte[] resBytes) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < resBytes.length; i++) {
            String hex = Integer.toHexString(resBytes[i] & 0xFF);
            if (hex.length() == 1) {
                hex = '0' + hex;
            }
            buffer.append(hex.toUpperCase());
        }
        return buffer.toString();
    }

    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();
    }
}