[英]Reading hex values from a String and storing them into an integer array in c/c++
我想問一下如何將字符串中的十六進制值存儲到整數數組中。 例如覆蓋
String sbox_str= "0x65, 0xea, 0xaf, 0x37, 0xff, 0x3b, 0xc2, 0xd0";
進入
uint8_t sbox[8]={0x65, 0xea, 0xaf, 0x37, 0xff, 0x3b, 0xc2, 0xd0};
如果您指導我如何在 QT Creator 中做同樣的事情,我將非常感激。
使用 QString 的簡單方法:
std::string sbox_str= "0x65, 0xea, 0xaf, 0x37, 0xff, 0x3b, 0xc2, 0xd0";
uint8_t sbox[8];
int i = 0;
for( const auto &item: QString(sbox_str.data()).split(", ")) {
if(i == sizeof (sbox)) break; // do something
sbox[i] = item.toInt(nullptr, 16);
++i;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.