Java和Android对Mac地址加1或者减1
/**
* Mac + 1
* @author YOLANDA
* @return
*/
public static String getMacAdd1(String mac){
String lastChar = mac.substring(mac.length() - 1).toUpperCase(Locale.getDefault());
mac = mac.substring(0, mac.length() - 1).toUpperCase(Locale.getDefault());
if("F".equals(lastChar)){
lastChar = "0";
} else {
int tempChar = Integer.parseInt(lastChar, 16) + 1;
lastChar = Integer.toHexString(tempChar).toUpperCase(Locale.getDefault());
}
return (mac + lastChar);
}
/**
* Mac减1
* @author YOLANDA
* @param mac
* @return
*/
public static String getMacMinus1(String mac){
String lastChar = mac.substring(mac.length() - 1).toUpperCase(Locale.getDefault());
mac = mac.substring(0, mac.length() - 1).toUpperCase(Locale.getDefault());
if("0".equals(lastChar)){
lastChar = "F";
} else {
int tempChar = Integer.parseInt(lastChar, 16) - 1;
lastChar = Integer.toHexString(tempChar).toUpperCase(Locale.getDefault());
}
return (mac + lastChar);
}