I need to convert an ASCII string like... "hello2" into it's decimal and or hexadecimal representation (a numeric form, the specific kind is irrelevant). So, "hello" would be : 68 65 6c 6c 6f 32 in HEX. How do I do this in C++ without just using a giant if statement?
dansnyderECE 0 Junior Poster
Recommended Answers
Jump to PostWhat exactly are you trying to solve? Why do you need its hex values? Are you hashing?
Jump to PostDon't really know what you are up to, but are you looking for something like this?
#include <iostream> #include <string> #include <cassert> #include <stdint.h> // C99, <cstdint> in C++0x uint64_t as_number( const std::string str ) { const unsigned int MAX_BYTES = sizeof(uint64_t) ; assert( str.size() <= MAX_BYTES …
All 5 Replies
sfuo 111 Practically a Master Poster
dansnyderECE 0 Junior Poster
mrnutty 761 Senior Poster
sfuo 111 Practically a Master Poster
vijayan121 1,152 Posting Virtuoso
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.