Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

binary to decimal online converter

//* How to convert a decimal number into a binary number
#include <bits/stdc++.h>
using namespace std;

class NumberConversion
{
    int n = 0, count = 0, ans = 0;

public:
    void decimalToBinary(int n)
    {
        this->n = n;
        while (this->n != 0)
        {
            int rem = this->n % 2;
            this->n /= 2;
            ans += rem * pow(10, count);
            count++;
        }
    }

    void display()
    {
        cout << ans << endl;
    }
};

int main()
{
    int number = 0;
    cin >> number;
    NumberConversion num1;
    num1.decimalToBinary(number);
    num1.display();

    return 0;
}
Source by math.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #binary #decimal #online #converter
ADD COMMENT
Topic
Name
7+5 =