I have to build a C++ code that accepts 4 separate Hexadecimal inputs and returns in English the human readable for a set of machine code instructions. I can either get my program to accept characters or integers. At this time I have my program set to work on integers from 0-9. That leaves me with A,B,C,D,E and F that will not work in my program. Is there a way to convert a user entered (cin) char to an integer?
Re: Converting Hexadecimal characters to integers.
Quote originally posted by Dave Sinkula ...
>Is there a way to convert a user entered (cin) char to an integer?
Why convert it, why not just use the chars '0', '1', ... 'A', 'B', ... ?
I did use characters at first. But when I use the switch statement, I need to compare the numbers for various case statements. I rely heavily on the arithmetic operations >,<,=,!=. If I can not use these operations my program will really be large. I was hoping that there was another way.
Re: Converting Hexadecimal characters to integers.
>Is there a way to convert a user entered (cin) char to an integer?
If you want to read each digit separately then it's a lot harder. Your best bet would be to read the entire number as a string and then parse it:
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.