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]
2 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]2 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
Percentage-wise, which renewable energy source is used most?
Natasha2012 [34]
C)Hydroelectric I believe.
5 0
3 years ago
n what sense is it now possible for a country to be ""occupied"" by an invisible invader that arrives through airwaves and wirel
Mademuasel [1]

Answer:

Option A. is correct

Explanation:

It now not possible for a country to be "occupied" by an invisible invader that arrives through airwaves and wireless networks. It is almost impossible to block foreign countries’ satellite broadcasts and Internet transmissions inspite of Spy satellites and other communications technology and Global positioning systems.

Option A. is correct

5 0
2 years ago
Help!! Best answer will get Brainliest!!
Eddi Din [679]

Answer:

answer(s):

-set goals

-select a topic

-write down research questions

Hope this helped and sorry for the bold. <3

Explanation:

6 0
2 years ago
Read 2 more answers
Anyone from qls<br><br>or grax here<br><br>in bs​
PIT_PIT [208]

Answer:

No, I don't think I've ever heard of DLS or Grax either if I'm being honest.

May I have brainliest please? :)

7 0
2 years ago
What is astronaut favourite key on keyboard? ​
Dennis_Churaev [7]

Answer:

The space bar is an astronauts favorite key

5 0
2 years ago
Read 2 more answers
Other questions:
  • What is the difference between chrome and chromium browser?
    9·1 answer
  • Given an array of n distinct integers,d = [d[0], d[1],.., d[n - 1]], and an integer threshold, t, how many (a,b,c) index triplet
    11·1 answer
  • .in the array based list implementation of the ADT what is the worst case time efficiency of the getEntry method?
    14·1 answer
  • Maggle is preparing a document. She wants to open the help menu to sort out a formatting problem. Which key should she press to
    11·1 answer
  • Rutherford concluded from his calculations that the volume of an atom is filled with protons, neutrons and electrons. is mostly
    14·1 answer
  • If your computer has a ________, someone else can gain access to it undetected.
    10·1 answer
  • The image below shows a weather service map
    13·1 answer
  • Computer network reduces the cost of operation​
    14·1 answer
  • Evaluate if the following function is a good candidate to be placed in a library. Why or why not?
    10·2 answers
  • WILL GIVE BRAINLIEST!!! Danielle is warehouse supervisor for a large shipping company. Most shipments need to leave the warehous
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!