1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marysya12 [62]
3 years ago
12

write a program that convert binary number to decimal. I mean the input should be binary number and the output decimal number!!.

Computers and Technology
1 answer:
wolverine [178]3 years ago
8 0

Answer:

#include<iostream>

#include<math.h>

using namespace std;

//main function

int main(){

   //initialization

   long b1;

   int d1=0,count_pos=0;

//display the message

   cout<<"Enter the binary number: ";

   cin>>b1;  //store the value

   //loop for take the digit one by one

   while(b1!=0){

       int rem1 = b1%10;

       d1 = d1 + rem1*pow(2,count_pos);

       count_pos++;

       b1 = b1/10;

   }

   //display the output

   cout<<"The decimal number is: "<<d1<<endl;

}

Explanation:

Create the main function and initialize the variables. Then, display the message on the screen by using the instruction cout and then, store the input enter by the user into the variable. Here, the variable declares with type 'long' because of the size of the input.

After that, we take a while loop for splitting the binary number into the digits and then we can do the operation.

Let's understand how you can convert binary to decimal with an example:

let the binary number is 1001:

decimal number is [tex]1*2^{3}+0*2^{2}+0*2^{1}+1*2^{0}=9[/tex]

we put the same algorithms in the code. split the number into digit and then multiply with n raised to the power of 2 here, n is the position of digit from left to right.

NOTE: Position starts from zero.

and then, add the values. this process continues until the number is not zero.

After that, display the output on the screen.

You might be interested in
PLEASEEE HELPPPP me
insens350 [35]

Answer:

D

Hope This Helps!   Have A Nice Day!!

7 0
3 years ago
2. What does the Action tool allow you to do in Microsoft PowerPoint? (20 points)
creativ13 [48]
B. Add actions

A. a presentation without a clear beginign middle and end

A. add action between slides
7 0
3 years ago
Read 2 more answers
What time is spellrd the same forwards and backwards​
Juliette [100K]
12:21 is the correct answer
6 0
2 years ago
Qbasic program to accept 10 numbers and to find their sum. <br>​
sesenic [268]

Answer:

the answer is 5

Explanation:

6 0
3 years ago
What is DAP? How LDAP is different from DAP?
lions [1.4K]

Answer: DAP stands for directory access protocol .It is a protocol that is used for accessing the information from the directory of X.500 protocol.

LDAP(Lightweight directory access protocol) is the software protocol that is present for the simplification process of the X.500 protocol and to make it light-weighted .It is basically a version of DAP in a lightweight form.

8 0
3 years ago
Other questions:
  • video-sharing sotes such as youtube and vimeo provide a place to post short videos called clips true or false?
    5·1 answer
  • In Microsoft Word you can access the _______ command from the "Mini toolbar
    11·1 answer
  • PLEASE HELP ME ON THIS..............PLEASEEEEEEEEEEEE PLEASEEEEEE<br><br> ITTS EASYYYYYYYY
    12·1 answer
  • In cell B20, enter a function to calculate the average attendance for 2018
    11·1 answer
  • Python3
    7·1 answer
  • 1. Which one of the following is true about screening interviews?
    7·1 answer
  • 5. Why do we need programming language?​
    13·2 answers
  • In the year, , the American Department of Defense put a military research network, called ARPANET online.
    5·1 answer
  • What is bigger that terbites
    10·2 answers
  • How ict tools changed the way we live explain it​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!