Solved

how do i get this to output in hexidecimal

Posted on 2004-09-19
2
222 Views
Last Modified: 2010-04-01
# include <iostream>

using namespace std;

int main(){

cout << "Please enter four ASCII characters: ";
char Num[500];  //<--- You must dimension proper size
gets(Num);


int len = strlen(Num);
std::hex;
Num[len+1] = Num[len+2] = Num[len+3] = 0;

0
Comment
Question by:tedschnieders
2 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12098447
To display an hex number just do this

cout << hex << aNumber;
0
 
LVL 1

Accepted Solution

by:
zekard earned 500 total points
ID: 12098853
tedschnieders,

two ways of doing this easy:

#include <iostream>

using namespace std;

int main()
{

      cout << "Please enter four ASCII characters: ";
      char Num[500];  //<--- You must dimension proper size
      gets(Num);

      // do something ...


      // integer array
      int iNum[500];
      for ( int i = 0; i < strlen ( Num ); i++ )
      {
            iNum[i] = Num[i];
      }

      for ( i = 0; i < strlen ( Num ); i++ )
      {
            cout << "0x" << hex << iNum[i] << endl;
      }

      return 0;

}

OR

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{

      cout << "Please enter four ASCII characters: ";
      char Num[500];  //<--- You must dimension proper size
      gets(Num);

      // do something ...

      for ( int i = 0; i < strlen ( Num ); i++ )
      {
            printf ( "0x%x\n", Num[i] );
      }
      return 0;

}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now