#include <bitset>
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
// Read a binary number into a bitset
cout << "Enter a binary number: ";
bitset< numeric_limits<unsigned long>::digits > bits;
cin >> bits;
unsigned long decimal_equivalent = bits.to_ulong();
cout << "Binary number: " << bits << "\nDecimal equivalent: " << decimal_equivalent;
}
|