我已經做了如何爲int以十六進制字符串轉換一些研究,發現一個answer,但是我需要的是一點點的不同,你可以在下面的代碼中看到:INT爲十六進制字符串(C++)
int addr = 5386; //
std::string buffer = "contains 0xCCCCCCCC as hex (non ASCII in the string)";
size_t idx = 0;
idx = buffer.find("\xCC\xCC\xCC\xCC", idx);
if (idx != string::npos) buffer.replace(idx, 4, XXX); // here i want to put the addr variable but as 0x0000150A
我需要做的是在addr
變量轉換爲已在字節之間的\x
等預先"\x0a\x15\x00\x00"
感謝一個十六進制字符串的方式。
你看看http://stackoverflow.com/questions/15823597/use-printf-to-print-character-string-十六進制格式扭曲結果? – Thomas
緩衝區包含八個字符'C'(0x43),但您搜索字符(0xCC)。這不匹配。你想實現什麼? – harper
@harper nope,正如我寫的那樣,緩衝區實際上包含4個字節作爲'cc:cc:cc:cc' –