Difference between revisions of "CPP/IntToHex"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==IntToHex.cxx== <source lang="cpp"> #include <iostream> #include <sstream> int IntToHex(int input); int main(int argc, char* argv[]) { int serial = 40000359; int serialHex…')
(No difference)

Revision as of 15:01, 25 January 2011

IntToHex.cxx

#include <iostream>
#include <sstream>
 
int IntToHex(int input);
 
int main(int argc, char* argv[])
{
  int serial = 40000359;
  int serialHex = (int)0x40000359;
  int convertedSerial = IntToHex(serial);
 
  std::cout << serialHex << std::endl;
  std::cout << convertedSerial << std::endl;
 
  return 0;
}
 
 
int IntToHex(int input)
{
  std::stringstream ss;
  std::string result;
  ss << "0x" << input;
  int output;
  ss >> std::hex >> output;
 
  return output;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
PROJECT(IntToHex)
 
ADD_EXECUTABLE(IntToHex IntToHex.cxx)