Advertisement
Guest User

Untitled

a guest
Oct 14th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include <sstream>
  4. using namespace std;
  5.  
  6. void print(string s, int num) {
  7. cout << "Hex value of " << num << " is : \n" << s << endl;
  8. }
  9. int main()
  10. {
  11. int num, rem, calc;
  12. char hexnum[100];
  13. int i = 1, j, temp;
  14. cout << "Enter the number please : ";
  15. cin >> num;
  16. calc = num;
  17. while (calc != 0)
  18. {
  19. temp = calc % 16;
  20. if (temp < 10)
  21. {
  22. temp = temp + 48;
  23. }
  24. else
  25. {
  26. temp = temp + 55;
  27. }
  28. hexnum[i++] = temp;
  29. calc = calc / 16;
  30. }
  31.  
  32. stringstream ss;
  33. for (j = i - 1; j > 0; j--)
  34. ss << hexnum[j];
  35.  
  36. string s = ss.str();
  37. print(s, num);
  38.  
  39. system("PAUSE");
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement