How do I convert a char* or an unsigned char* to an unsigned int?
lil_panda
0
Light Poster
Recommended Answers
Jump to PostIf you want to use pure c++ then use stringstream c++ class.
Jump to Poststill use strtol()
int main() { char hex[]= "ABCD"; char* end = 0; unsigned int num = strtol(hex,&end,16); cout << num << "\n"; }
Jump to Post>still use strtol()
Better to use stringstream:#include <ios> #include <iostream> #include <sstream> int main() { using namespace std; istringstream is("ABCD"); unsigned int num; if (is >> hex >> num) cout << num << '\n'; }
// Confusing name choice char hex[]= "ABCD";
hex …
All 9 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
lil_panda
0
Light Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Radical Edward
301
Posting Pro
Ancient Dragon
commented:
Agree -- you have a better solution for c++
+34
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
lil_panda
0
Light Poster
Radical Edward
301
Posting Pro
lil_panda
0
Light Poster
Radical Edward
301
Posting Pro
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.