DEV Community 👩‍💻👨‍💻

Analyze_
Analyze_

Posted on

cpp Binary to Decimal decoder

Since my (last post) I had been trying to make a Binary to Decimal calculator, also using C++. I went for a different method this time, and now the binary supports over 8 digits.

Credit to: https://geeksforgeeks.org/

Link to finished project

Code:

#include <iostream>
using namespace std;

int main() {
  char binaryNumber[] = "0101010101010101010101010101010101";
  string session = "y";
  while (session == "y") {

    cout << "\nEnter a Binary number (1s and 0s): ";
    cin >> binaryNumber;
    cout << "\n";

    cout << stoi(binaryNumber, 0, 2);
    session = "y";
    cout << "\nContinue session? [y/n]\n";
    cin >> session;
    cout << "\x1B[2J\x1B[H";
  } // end of session
  cout << "Credit to https://geeksforgeeks.org/ for helping me with some of "
          "this code!\n";
  return 1;
}
Enter fullscreen mode Exit fullscreen mode

`
Changelog#1(Fri, Jun 3rd):
Fixed formatting

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.