I wrote a program that used recursion to convert between the number bases some time ago. I am currently working on some pointer values (for class objects) in hex and would like to convert these to integers for use in an array. Instead of having to include a header file for the base-conversion program I have, I am just wondering if the C++ library has in-built base-conversion functions I can readily use; I couldn't find any when I searched through it!
I know kbw; but what I'm asking is if in-built, system-defined functions exist that perform base conversions. Like I wrote earlier, I already did write a recursive program to do just that; but, in my pursuit of minimalism in coding, I just would like to exploit the C++ library's provisions if such base-conversion functions are available. I'm guessing there aren't.
I didn't see your post before my last post! Is that 'stoi' an in-built C++ function? I'm guessing it stands for 'string-to-integer', right? Are there any you know of for conversions between the number bases??
I am not entering the pointer values as data; the system generated them(in hex) as the addresses of the class objects I'm working on, in response to the manipulation, using pointers, of a particular data member across all the objects. To ascertain the correctness of the data processing, I printed a list of the addresses of the objects - the sequence I obtained indicated that the desired computation was achieved.
However, I need to find a way of converting these addresses into integers to be stored in an array through the use of an in-built, base-conversion function, if available. At least, that was my initial motive! But now, I'm just thinking probably I should just store the addresses as string constants and access the array later as such. Moreso now that no one seems to be able to come up with such relevant in-built function! Currently, I have declared that array as of type integer.
@JLBorges,Three questions for you:
#1. Am I right to infer from your post that there is no in-built function to do what I want; I just have to write a conversion function myself? #2. What is that stoull() function you invoked in your code? #3. I see unsignedlonglong in your code; does that duplication serve to augment the maximum size of the integer allowed? In other words, is it correct to deduce that unsignedlonglong can store a much larger integer than unsignedlong(which I'm more used to)?
However, you may find that std::stoull() and friends are missing from your library. Some implementations (for instance the GNU libstdc++) have not yet implemented this function. In which case, you have to write a function yourself as a temporary work around.
The types longlong and unsignedlonglong were added in C++11. These are expected to be at least 64 bits wide, and on almost all implementations have a wider range than long / unsignedlong.
See the table at the end of this page: http://en.cppreference.com/w/cpp/language/types