StringStream in C++ for Decimal to Hexadecimal and back
Stringstream is stream class present in C++ which is used for doing operations on a string. It can be used for formatting/parsing/converting a string to number/char etc. Hex is an I/O manipulator that takes reference to an I/O stream as parameter and returns reference to the stream after manipulation. Here is a quick way to convert any decimal to hexadecimal using stringstream:
The time complexity of this program is O(1) as it only performs a single operation.
The space complexity is also O(1) as no additional space is used.
If we want to change hexadecimal string back to decimal you can do it by following way:
Time Complexity: The time complexity of the above algorithm is O(1), as we are only performing a few operations.
Space Complexity: The space complexity of the above algorithm is O(1), as we are only using a few variables.
Please Login to comment...