Solved

how do i get this to output in hexidecimal

Posted on 2004-09-19
2
226 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

821 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