Solved

how do i get this to output in hexidecimal

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

760 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

18 Experts available now in Live!

Get 1:1 Help Now