| | |
Converting Hexadecimal characters to integers.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
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?
Any help would be greatly appreciated.
John
Any help would be greatly appreciated.
John
>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', ... ?
Why convert it, why not just use the chars '0', '1', ... 'A', 'B', ... ?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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', ... ?
John
>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:
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:
C++ Syntax (Toggle Plain Text)
#include <cctype> #include <iostream> #include <string> using namespace std; int main() { string s; if ( getline ( cin, s ) ) { static string hex_digits ( "0123456789ABCDEF" ); string::const_iterator it = s.begin(); string::const_iterator end = s.end(); for ( ; it != end; it++ ) { string::size_type val = hex_digits.find ( toupper ( *it ) ); if ( val != string::npos ) cout<<"The value of "<< *it <<" is "<< val <<endl; } } }
New members chased away this month: 4
![]() |
Similar Threads
- HELP!!! Converting Hexadecimal to Decimal or vice versa (MS SQL)
- qsort Confusion (C++)
- help with loops (C++)
- CRC Calculation (Visual Basic 4 / 5 / 6)
- input bianary ASCII converted into Characters (C)
Other Threads in the C++ Forum
- Previous Thread: Plz. Help me get my program to work
- Next Thread: Need help setting up graphics
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int java lib library lines linkedlist linker loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return sort string strings struct studio system temperature template templates test text text-file tree unix url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






