C ++ reads binary data and converts it to decimal output.
Description
It is known that a binary number containing only 0 and 1 is not greater than 10 in length. convert it to decimal and output.
Input description
Enter a binary integer n with a length not greater than 10.
Output description
The number of decimal lines after the output is converted.
Sample Input
110
Sample output
6
Solution:
Many people who have studied C ++ may think of reading another character in the form of a character array and calculating it as a decimal output.
No.
The C ++ Class Library provides binary data classes and can be converted to decimal using the method.
The Code is as follows:
1 # include <iostream> 2 using namespace std; 3 4 # include <bitset> 5 6 int main () 7 {8 bitset <16> bint; // 16 bit binary data, bitset <32> 9 10 cin> bint; 11 cout <bint. to_ulong () <endl; 12 13 return 0; 14}