简体   繁体   中英

Equivalent in C++ to the pack function in PHP pack('H*', $tagIdAsHex);

I have this PHP code:

$tagId = 1;    // the original value of tag
$tagIdAsHex = sprintf("%02X", $tagId);    // the tag value in hex format
$tagAsHexBytes = pack('H*', $tagIdAsHex);  // the packed hex value of tag packed into string as a conversion 

How can I translate that to C++?

byte tagId = 1;
auto hexedTag = IntToHex(tagId); //C++ Builder
??

The PHP code shown is simply converting the integer 1<\/code> into a hex-encoded string<\/code> containing "01"<\/code> , and is then parsing that hex string<\/code> into a binary string<\/code> holding a single byte 0x01<\/code> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM