
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert an integer to a hex string in C++
In this program we will see how to convert an integer to hex string. To convert an integer into hexadecimal string we can follow mathematical steps. But in this case we have solved this problem using simple trick.
In C / C++ there is a format specifier %X. It prints the value of some variable into hexadecimal form. We have used this format specifier to convert number into a string by using sprintf() function.
Input: An integer number 255 Output: FF
Algorithm
Step 1:Take a number from the user Step 2: Make a string after converting number using %X format specifier Step 3: Print the result. Step 4: End
Example Code
#include<iostream> using namespace std; main() { int n; char hex_string[20]; cout << "Enter a number: "; cin >> n; sprintf(hex_string, "%X", n); //convert number to hex cout << hex_string; }
Output
Enter a number: 250 FA
- Related Questions & Answers
- Convert Integer to Hex String in Java
- How to convert a color integer to a hex String in Android?
- How to Convert Hex String to Hex Number in C#?
- Convert a String to Integer Array in C/C++
- Convert hex string to number in MySQL?
- How to convert a string to a integer in C
- C# Program to Convert Integer to String
- How to convert an integer to a hexadecimal string in Python?
- How to convert an integer to a octal string in Python?
- Convert byte Array to Hex String in Java
- Convert Hex String to byte Array in Java
- How to convert an integer to string with padding zero in C#?
- Python program to convert hex string to decimal
- How to convert Int to Hex String in Kotlin?
- How to convert a byte array to hex string in Java?
Advertisements