CPP/IntToHex

From ProgrammingExamples
< CPP
Revision as of 00:12, 15 June 2011 by Newacct (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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;
  ss << input;
  int output;
  ss >> std::hex >> output;
 
  return output;
}

CMakeLists.txt

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