Hex to Decimal/ Search in a string/ How to use MSDN?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to acquire data from a USB device. The device
send to PC data in strings like "0xa0 oxa1 oxa2...". I should
have to :

1,searching in the strings and pick up useful data like "0xa1",
"0xa2" and so so.
2,convert them from Hex data to decimal data.
3,save to a array.

How could I do it?

I am a new commer. I often find that I can't find the right place
in MSDN for the questions. Would you tell me how to use MSDN for
the above questions?
 
Hi yinyz!
I would like to acquire data from a USB device. The device
send to PC data in strings like "0xa0 oxa1 oxa2...". I should
have to :

1,searching in the strings and pick up useful data like "0xa1",
"0xa2" and so so.
2,convert them from Hex data to decimal data.
3,save to a array.

1. Use "strtok" to separate the string
2. Use strtol(..., 16) to convert to int
3. Store it in an int-array or std::vector<int>

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
yinyz said:
I would like to acquire data from a USB device. The device
send to PC data in strings like "0xa0 oxa1 oxa2...". I should
have to :

1,searching in the strings and pick up useful data like "0xa1",
"0xa2" and so so.
2,convert them from Hex data to decimal data.
3,save to a array.

How could I do it?

You could use string streams:

#include <sstream>

//...
std::vector<int> result;
std::istringstream iss("0xa0 0xa1 0xa2");
for(;;) {
int i;
iss >> std::hex >> i;
if( !iss.good() ) break;
result.push_back(i);
}
if( !iss.eof() ) error();
//...
I am a new commer. I often find that I can't find the right place
in MSDN for the questions. Would you tell me how to use MSDN for
the above questions?


I don't think you'll find an explanation
for the above in the MSDN lib. It's a
reference, not a text book.

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

"Coming back to where you started is not the same as never leaving"
Terry Pratchett
 
Back
Top