As the title says I try to convert to byte data type a C++ String of Bytes and count bytes.
The string I get from textbox will contain a series of one byte hexadecimal numbers, but I need to send it as bytes.
char packet_data[200];
HWND hTextBox2 = GetDlgItem(TabOneDlg,IDC_EDIT3);
SendMessageA(hTextBox2, WM_GETTEXT, (WPARAM)200, (LPARAM)packet_data);
That’s how I get the input value (I am using win32 API – unmanaged forms)
EXAMPLE of input string (hex)
AA BB CC DD - 4 bytes !
In SHORT I want to do this :
Got a string containing a textual representation of hexadecimal numbers, and I want to convert each textual representation of the hexadecimal numbers to “normal” numbers.
If you are sure that the hexadecimal numbers are separated by a space (as shown in the question) it is a simple question of extracting them. The simplest way in C++ is by using
std::istringstreamand the normal input operator>>:After the above code, the vector
datawill have all data from the string. If you need to e.g. send the data over a socket (or similar) you can usestd::vector::datato get a raw pointer to the data (or use&data[0]if thedatafunction doesn’t exist), and the number of bytes is available fromstd::vector::size.