Java Formatter Usage generateMacOnIncrease(final String baseMac, final long l)

Here you can find the source of generateMacOnIncrease(final String baseMac, final long l)

Description

generate Mac On Increase

License

Apache License

Declaration

public static String generateMacOnIncrease(final String baseMac,
            final long l) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

import java.util.Formatter;

public class Main {
    public static String generateMacOnIncrease(final String baseMac,
            final long l) {
        long mac = mac2Long(baseMac);
        if (l > 0xFFFFl) {
            return null;
        }/*from   w  w w. j a va2  s. c o  m*/
        mac = mac + (l << 24);
        mac = mac & 0x06FFFFFFFFFFl;
        return long2Mac(mac);
    }

    public static long mac2Long(final String macAddress) {
        final String[] tokens = macAddress.split(":");
        assert tokens.length == 6;
        long result = 0;
        for (int i = 0; i < tokens.length; i++) {
            result = result << 8;
            result |= Integer.parseInt(tokens[i], 16);
        }
        return result;
    }

    public static String long2Mac(final long macAddress) {
        final StringBuilder result = new StringBuilder(17);
        try (Formatter formatter = new Formatter(result)) {
            formatter.format("%02x:%02x:%02x:%02x:%02x:%02x",
                    macAddress >> 40 & 0xff, macAddress >> 32 & 0xff,
                    macAddress >> 24 & 0xff, macAddress >> 16 & 0xff,
                    macAddress >> 8 & 0xff, macAddress & 0xff);
        }
        return result.toString();
    }
}

Related

  1. formatResponse(Formatter formatter, String response)
  2. formatTzname(final String format, final String letter)
  3. formatv(String format, Object[] args)
  4. formatZeroDecimals(Number x)
  5. fperfdata(String label, double val, String uom, int warnp, double warn, int critp, double crit, boolean minp, double minv, boolean maxp, double maxv)
  6. getCommitCounterStr(final long commitCounter)
  7. getFormatedTime(double timeInSeconds)
  8. getPropertiesString(Properties myProps)
  9. GetRawView(String string)