Answer to Question #283426 in C++ for Rudy

Question #283426

Write a code which demonstrates the use of hex,oct,dec manipulators



1
Expert's answer
2021-12-29T02:19:52-0500
#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';
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog