Java Utililty Methods Mac Address to String

List of utility methods to do Mac Address to String

Description

The list of methods to do Mac Address to String are organized into topic(s).

Method

byte[]macToBinary(String mac)
mac To Binary
byte[] macBytes = new byte[6];
try {
    String[] strArr = mac.split(":");
    for (int i = 0; i < strArr.length; i++) {
        int value = Integer.parseInt(strArr[i], 16);
        macBytes[i] = (byte) value;
} catch (Exception e) {
...
StringmacToStr(byte[] mac)
Converts a MAC address to colon hexadecimal representation (e.g., "00:01:02:03:04:05").
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
    strBuilder.append(String.format("%02X", mac[i]));
    if (i < mac.length - 1) {
        strBuilder.append(":");
return strBuilder.toString();
...
StringmacToString(byte[] mac)
mac To String
StringBuilder b = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
    b.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? ":" : ""));
return b.toString();
StringmacToString(byte[] mac)
mac To String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 6; i++) {
    String octet = (Integer.toHexString(mac[i] & 0xFF)).toUpperCase();
    if (octet.length() == 1) {
        sb.append("0");
    sb.append(octet);
    if (i != 5) {
...
StringmacToString(final byte[] address)
Convert specified array of bytes into an mac address string.
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();
...
StringmacToString(long macAddress)
mac To String
String value = String.format("%012x", macAddress);
char[] chars = value.toCharArray();
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(chars[0]).append(chars[1]);
for (int pos = 2; pos < value.length(); pos += 2) {
    stringBuilder.append(":").append(chars[pos]).append(chars[pos + 1]);
return stringBuilder.toString();
...
StringmacToString(String srcstr)
mac To String
if (srcstr == null) {
    return "null";
StringBuffer buf = new StringBuffer();
for (int i = 0; i < srcstr.length(); i = i + 3) {
    buf.append(srcstr.charAt(i));
    buf.append(srcstr.charAt(i + 1));
return buf.toString();