Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::hex

 

std::hex is a stream manipulator to system the number system to hexadecimal.

 

The example below shows how to display an integer in hexadecimal, octal and decimal with or without showing the number system base.

 

#include <iostream>

int main ()
{
  const int x = 100;
  std::cout
    << "The value of x in hex: "
    << std::hex
    << std::showbase
    << x << '\n';
  std::cout
    << "The value of x in oct: "
    << std::oct
    << std::showbase
    << x << '\n';
  std::cout
    << "The value of x in dec: "
    << std::dec
    << std::noshowbase
    << x << '\n';
}

 

Screen output:

 

The value of x in hex: 0x64
The value of x in oct: 0144
The value of x in dec: 100

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict