// Because the system cannot reply, the system always prompts an incorrect verification code.
# Include "stdafx. H"
# Include <iostream>
# Include <string>
# Include <cstdlib>
# Include <bitset>
# Include <iomanip>
# Include <cassert>
# Include <limits>
Using namespace STD;
Typedef Enum _ transmode
{
Hex_mode = 1,
Dec_mode,
Oct_mode
} Transmode;
Int main ()
{
String instr; // This is the input, string type
Long outlong; // converts the value to a long integer in the hexadecimal format.
Int n_numformat;
Cout <"Please chose the input number format (1-Hex, 2-dec, 3-oct)" <Endl;
Cin> n_numformat;
Cout <"Please input the number to be transformed :";
Cin> instr;
Switch (n_numformat) // your style is better than mine
{
Case hex_mode:
N_numformat = 16;
Break;
Case dec_mode:
N_numformat = 10;
Break;
Case oct_mode:
N_numformat = 8;
Break;
Default:
Cout <"error input number, exit" <Endl;
Exit (1 );
}
Outlong = strtol (instr. c_str (), null, n_numformat );
Assert (outlong! = 0); // If the conversion fails and the assertions are incorrect, this is the best part of your method.
Bitset <numeric_limits <long>: digits> abit (outlong );
Cout <"the binary number is" <abit <Endl; // No pipe format
Return 0;
}