Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    private static void test_parseBssid() {
        byte b[] = { 15, -2, 52, -102, -93, -60 };
        if (parseBssid(b).equals("0ffe349aa3c4")) {
            System.out.println("test_parseBssid(): pass");
        } else {
            System.out.println("test_parseBssid(): fail");
        }
    }

    public static String parseBssid(byte[] bssidBytes, int offset, int count) {
        byte[] bytes = new byte[count];
        for (int i = 0; i < count; i++) {
            bytes[i] = bssidBytes[i + offset];
        }
        return parseBssid(bytes);
    }

    /**
     * parse "24,-2,52,-102,-93,-60" to "18,fe,34,9a,a3,c4"
     * parse the bssid from hex to String
     * @param bssidBytes the hex bytes bssid, e.g. {24,-2,52,-102,-93,-60}
     * @return the String of bssid, e.g. 18fe349aa3c4
     */
    public static String parseBssid(byte[] bssidBytes) {
        StringBuilder sb = new StringBuilder();
        int k;
        String hexK;
        String str;
        for (int i = 0; i < bssidBytes.length; i++) {
            k = 0xff & bssidBytes[i];
            hexK = Integer.toHexString(k);
            str = ((k < 16) ? ("0" + hexK) : (hexK));
            System.out.println(str);
            sb.append(str);
        }
        return sb.toString();
    }
}