void ui_mac_ntoa(const unsigned char *n, char *a, const char *d) { sprintf(a, "%02x%s%02x%s%02x%s%02x%s%02x%s%02x", n[0], d, n[1], d, n[2], d, n[3], d, n[4], d, n[5]); }
//////mac -> 6
void ui_mac_aton(const char *a, unsigned char *n, const char *d) { char buf[30] = {0}; const char *upper = buf; char ch[3] = {0}; int nf = 0, ns = 0, nt = 2 + strlen(d); strcpy(buf, a); ui_strupper(buf); for (unsigned int index = 0; index < 6; index++) { strncpy(ch, upper + index * nt, 2); nf = (ch[0] >= '0' && ch[0] <= '9') ? (ch[0] - '0') : (ch[0] - 'A') + 10; ns = (ch[1] >= '0' && ch[1] <= '9') ? (ch[1] - '0') : (ch[1] - 'A') + 10; *(n + index) = (unsigned char)(nf * 16 + ns); } }
//////mac -> 6
void ui_mac_aton(const char *a, unsigned char *n, const char *d) { char buf[30] = {0}; const char *upper = buf; char ch[3] = {0}; int nf = 0, ns = 0, nt = 2 + strlen(d); strcpy(buf, a); ui_strupper(buf); for (unsigned int index = 0; index < 6; index++) { strncpy(ch, upper + index * nt, 2); nf = (ch[0] >= '0' && ch[0] <= '9') ? (ch[0] - '0') : (ch[0] - 'A') + 10; ns = (ch[1] >= '0' && ch[1] <= '9') ? (ch[1] - '0') : (ch[1] - 'A') + 10; *(n + index) = (unsigned char)(nf * 16 + ns); } }
return String.format(
"%02x%s%02x%s%02x%s%02x%s%02x%s%02x",
n.charAt(0), d, n.charAt(1), d, n.charAt(2), d, n.charAt(3), d, n.charAt(4), d, n.charAt(5)); }
第二个凭感觉写一下,估计会有问题,自己调试String ui_mac_aton(String a,String n,String d) {
StringBuilder buf = new StringBuilder();
String upper = buf.toString(); //不太清楚这个upper是怎么处理的
byte[] ch = byte[3]; int nf = 0,ns = 0;
int nt = 2 + d.length(); buf.append(a); //ui_strupper(buf); 这个函数干吗的?? 不知道
for (int index = 0; index < 6; index++) { //upper的赋值可能有问题
ch[0] = upper.charAt(index*nt);
ch[1] = upper.charAt(index*nt + 1);
nf = (ch[0] >= '0' && ch[0] <= '9') ? (ch[0] - '0') : (ch[0] - 'A') + 10; ns = (ch[1] >= '0' && ch[1] <= '9') ? (ch[1] - '0') : (ch[1] - 'A') + 10;
n.charAt(index) = (char)(nf * 16 + ns); }return n;
}