Here you can find the source of macToString(final byte[] address)
Parameter | Description |
---|---|
address | the address |
public static String macToString(final byte[] address)
//package com.java2s; public class Main { /**//from w w w . j a v a 2 s.c om * Convert specified array of bytes into an mac address string. * * @param address the address * @return the mac address string */ public static String macToString(final byte[] address) { final StringBuffer sb = new StringBuffer(address.length * 3); for (int i = 0; i < address.length; i++) { if (0 != i) { sb.append(':'); } appendHexValue(sb, address[i]); } return sb.toString(); } /** * Convert a byte into hex value and add to buffer. * * @param sb the StringBuffer. * @param data the data. */ static void appendHexValue(final StringBuffer sb, final byte data) { sb.append(nibbleToHex((byte) (data >> 4))); sb.append(nibbleToHex(data)); } /** * Convert lower 4 bits into a hex character. * * @param data the data byte * @return the hex character */ static char nibbleToHex(final byte data) { final int nibble = data & 0xf; if (nibble <= 9) { return (char) ('0' + nibble); } else { return (char) ('A' + nibble - 10); } } }