Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how do i get this to output in hexidecimal

Posted on 2004-09-19
2
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

688 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