0

I'm not good in C++

I have a code C++, and I want to convert from std::string to BYTE

The original code is

BYTE APDU_Cmd1[] = { 0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 };

lReturn = SCardTransmit(hCardHandle, &pioSendPci, APDU_Cmd1, sizeof(APDU_Cmd1), NULL, pbRecv, &dwRecv);

I want to change it to be like this

std::string APDU_Cmd1="A0A40000023F00";

how to convert string APDU_Cmd1 to BYTE APDU_Cmd1[] ?

Thanks in advance .

  • if you want to store bytes in string, you can copy them to string, like `std::string str = std::string(std::begin(bytes), std::end(bytes));`. if you want constant byte string, you can prepend hex with `\x` escape `std::string str = "\xA0\xA4\x00\x00";`. if you want textual hexademical representation, you need to convert each byte to two characters from hex alphabet. – Ruslan Tushov Sep 18 '21 at 08:33
  • I want to get every two characters of a string in an array byte and add 0x format HEX , Convert this ( std::string APDU_Cmd1="A0A40000023F00"; ) to (BYTE APDU_Cmd1[] = { 0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 };) – Ma7moud.fadl Sep 18 '21 at 08:46
  • https://stackoverflow.com/questions/3381614/c-convert-string-to-hexadecimal-and-vice-versa – Barmak Shemirani Sep 18 '21 at 14:47

0 Answers0