DEV Community

Analyze_
Analyze_

Posted on

5 4

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

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs