Convert Network mac Address To Bytes - Android Network

Android examples for Network:Network Status

Description

Convert Network mac Address To Bytes

Demo Code


//package com.java2s;

public class Main {
    public static byte[] macToBytes(String mac) {
        byte[] resBytes = new byte[6];
        resBytes[0] = (byte) Integer.parseInt(mac.substring(0, 2), 16);
        resBytes[1] = (byte) Integer.parseInt(mac.substring(2, 4), 16);
        resBytes[2] = (byte) Integer.parseInt(mac.substring(4, 6), 16);
        resBytes[3] = (byte) Integer.parseInt(mac.substring(6, 8), 16);
        resBytes[4] = (byte) Integer.parseInt(mac.substring(8, 10), 16);
        resBytes[5] = (byte) Integer.parseInt(mac.substring(10, 12), 16);
        return resBytes;
    }/*from  ww w . j a  v  a  2s  .co  m*/
}

Related Tutorials