Home   |   About   |   Terms   |   Contact    
Read & Learn
 

How to display a value in Hexadecimal form in C++?

C++

☯ All C++ Articles     ☯ All Articles


A new product.






Popular Google Pages:




This article is regarding How to display a value in Hexadecimal form in C++?
Last updated on: .

◕ how to display a value in Hexadecimal form in C++?

- If we want to display a value in hexadecimal form we have to use some special features of cout. For an example, the iostream header file provides the endl manipulator to give cout the message to start a new line. Similarly, it provides the hex manipulators to give cout the messages to display integers in hexadecimal form.



■ The example is given bellow.

Let we have a program like this:

#include <iostream>
using namespace std;
int main(){
int street = 13; // this is in Decimal form
cout << hex;
cout << "Displaying Decimal in Hexadecimal form: " << street << endl;
return 0;
}

The output is:
Displaying Decimal in Hexadecimal form: d



Please note:
The code cout << hex; doesn’t display anything onscreen. Instead, it changes how the cout will display the integers in Hexadecimal. This hex is a Manipulator. This manipulator gives a message to cout which tells it how to behave with the integer.



Related article:
How to display a value in Hexadecimal form in C++?
How to display a value in Octal form in C++?
How C++ identify the base of a number?



Popular Google Pages:



Top of the page

Amazon & Flipkart Special Products

   


Top of the page