Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include <sstream>
- using namespace std;
- void print(string s, int num) {
- cout << "Hex value of " << num << " is : \n" << s << endl;
- }
- int main()
- {
- int num, rem, calc;
- char hexnum[100];
- int i = 1, j, temp;
- cout << "Enter the number please : ";
- cin >> num;
- calc = num;
- while (calc != 0)
- {
- temp = calc % 16;
- if (temp < 10)
- {
- temp = temp + 48;
- }
- else
- {
- temp = temp + 55;
- }
- hexnum[i++] = temp;
- calc = calc / 16;
- }
- stringstream ss;
- for (j = i - 1; j > 0; j--)
- ss << hexnum[j];
- string s = ss.str();
- print(s, num);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement