mac地址字符串转unsigned char数组
时间: 2023-11-07 14:01:27 浏览: 272
要将mac地址字符串转换为unsigned char数组,您可以使用以下代码:
```
QString macAddress = "A1-B2-C3-D4-E5-F6";
QVector<unsigned char> byteArray = hexStringToByteArray(macAddress);
// 将QVector<unsigned char>转换为unsigned char数组
unsigned char* byteArr = byteArray.data();
```
下面是实现hexStringToByteArray函数的代码:
```
QVector<unsigned char> hexStringToByteArray(const QString& strMac) {
QVector<unsigned char> vecMac;
if (strMac.size() != 17) {
return vecMac;
}
for (int i = 0; i < strMac.size(); i += 3) {
QString num = strMac.mid(i, 2);
bool ok = false;
vecMac.push_back(num.toUInt(&ok, 16));
if (!ok) {
return QVector<unsigned char>();
}
}
return vecMac;
}
```
阅读全文