C ++ cout conversion format output (octal and hexadecimal), cout hexadecimal
// Hex, oct output # include <iostream> using namespace std; int main () {int chest = 42, waist = 42, inseam = 42; cout <"chest =" <chest <"(decimal for 42)" <endl; cout
How to convert hexadecimal to octal in C ++
The computer is in binary mode, and the input and output are only reflected in other hexadecimal modes.
# Include <iostream>
# Include <iomanip>
Using namespace std;
Main (){
Int x;
Cout <"input hex data" <endl;
Cin> hex> x; // The number of inputs in this method is in hexadecimal notation.
Cout <oct <x <endl; // The number output by this method is in octal format.
}
By the way, the input/output % x format in C language is hexadecimal and % o is octal.
The user enters a decimal positive integer and converts it to binary, octal, and hexadecimal output (C ++, not C)
# Include <iostream>
Using namespace std;
Int main ()
{
Int a, B, c, d;
Cout <"Enter the number to be converted :";
Cin>;
// Calculate each bit in binary format
If (a = 0) cout <;
B = a; c = 0; d = 1;
While (B! = 0)
{
C + = (B % 2) * d; // write the remainder of B divided by 2 in sequence at the corresponding position of c.
B = B/2;
D * = 10;
}
Cout <c <endl;
// The octal and hex formats are formatted and output. oct indicates octal and hex indicates hexadecimal.
Cout <oct <a <endl;
Cout }
If you have any questions, contact us.