Write a code which demonstrates the use of hex,oct,dec manipulators
#include <iostream>
#include <sstream>
#include <bitset>
using namespace std;
int main()
{
cout << "The number 42 in octal: " << oct << 42 << '\n'
<< "The number 42 in decimal: " << dec << 42 << '\n'
<< "The number 42 in hex: " << hex << 42 << '\n';
int n;
istringstream("2A") >> hex >> n;
cout << dec << "Parsing \"2A\" as hex gives " << n << '\n';
cout << hex << "42 as hex gives " << 42
<< " and 21 as hex gives " << 21 << '\n';
cout << "The number 42 in binary: " << bitset<8>{42} << '\n';
}
Comments
Leave a comment