Solved

how do i get this to output in hexidecimal

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

734 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