Java Long to long2MacAddress(long l)

Here you can find the source of long2MacAddress(long l)

Description

long Mac Address

License

Open Source License

Declaration

public static String long2MacAddress(long l) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String long2MacAddress(long l) {
        StringBuilder sb = new StringBuilder(17);
        sb.append(toHex((byte) ((l >> 44) & 0xf)));
        sb.append(toHex((byte) ((l >> 40) & 0xf)));
        sb.append(":");
        sb.append(toHex((byte) ((l >> 36) & 0xf)));
        sb.append(toHex((byte) ((l >> 32) & 0xf)));
        sb.append(":");
        sb.append(toHex((byte) ((l >> 38) & 0xf)));
        sb.append(toHex((byte) ((l >> 24) & 0xf)));
        sb.append(":");
        sb.append(toHex((byte) ((l >> 20) & 0xf)));
        sb.append(toHex((byte) ((l >> 16) & 0xf)));
        sb.append(":");
        sb.append(toHex((byte) ((l >> 12) & 0xf)));
        sb.append(toHex((byte) ((l >> 8) & 0xf)));
        sb.append(":");
        sb.append(toHex((byte) ((l >> 4) & 0xf)));
        sb.append(toHex((byte) (l & 0xf)));
        return sb.toString();
    }//w w w. ja  v  a2s.co  m

    public static char toHex(byte lowByte) {
        assert (lowByte < 16);
        if (lowByte < 10) {
            return (char) ('0' + lowByte);
        } else if (lowByte < 16) {
            return (char) ('A' + lowByte - 10);
        } else {
            return '?';
        }
    }
}

Related

  1. long2dotted(long address)
  2. long2FourChars(long i)
  3. Long2H(final long l)
  4. long2leb(final long x, final byte[] buf, final int offset)
  5. long2longArr(long val, long[] res)
  6. long2minLeb(final long x)
  7. longTo36Str(String str)
  8. longTo4ByteArray(byte[] bytes, int offset, long value)
  9. longTo4LengthBytes(long num)