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
Savatey [412]
3 years ago
9

Implement function bin2dec that takes a binary number bin_num as a string argument and prints out the corresponding decimal numb

er. Each char in the string has a value of either '0' or '1' to represent a bit. The string does not have any leading space. For example, function call bin2dec("1011") should print 11. You can assume that bin_num can have up to 32 bits. To convert a char in the binary number string to an int, you can subtract the char by '0'. For example, you can use bin_num[0] - '0' to get the int value of the most significant bit of the binary number. Restriction: printf is the ONLY C library function that you can use in the implementation.
Computers and Technology
1 answer:
andriy [413]3 years ago
7 0

Answer:

See explaination

Explanation:

void bin2dec(char *s) {

int i = 0, num = 0;

while (s[i]) {

num *= 2;

num += s[i] - '0';

i++;

}

printf("%d\n", num);

}

The program Implement function bin2dec that takes a binary number bin_num as a string argument and prints out the corresponding decimal number.

You might be interested in
Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single
Delicious77 [7]

Answer:

Check the explanation

Explanation:

#include <iostream>

#include <string>

using namespace std;

string decimalToBinaryRecursive(int n) {

   if(n == 0) {

       return "0";

   } else if(n == 1) {

       return "1";

   } else {

       int d = n % 2;

       string s;

       if (d == 0) {

           s = "0";

       } else {

           s = "1";

       }

       return decimalToBinaryRecursive(n/2) + s;

   }

}

int main() {

   cout << decimalToBinaryRecursive(0) << endl;

   cout << decimalToBinaryRecursive(1) << endl;

   cout << decimalToBinaryRecursive(8) << endl;

   return 0;

}

See the output image below

5 0
3 years ago
Write a program that converst the temperature from Celcius to Fahrenheit. The formula is: F (9/5)C+32
gregori [183]

Answer:

F

=

9

5

C

+

32

Subtract 32 from both sides:

F

−

32

=

9

5

C

Multiply both sides by 5:

5

(

F

−

32

)

=

9

C

Divide both sides by 9:

5

9

(

F

−

32

)

=

C

or  

C

=

5

9

(

F

−

32

)

Explanation:

6 0
3 years ago
Read 2 more answers
How do I indent the 1. bullet so it is not lined up with the regular bullet above it?
Neko [114]

Answer:

Change bullet indents

Select the bullets in the list by clicking a bullet. ...

Right-click, and then click Adjust List Indents.

Change the distance of the bullet indent from the margin by clicking the arrows in the Bullet position box, or change the distance between the bullet and the text by clicking the arrows in the Text indent box.

Explanation:

mark me braineliest

8 0
3 years ago
Dams provide what kind of energy ?
Leto [7]
Water energy to supply anything
6 0
3 years ago
Read 2 more answers
1 Explain the difference between using a computer program and programming a computer.
Zanzabum
Well when you are using a computer program you are using a program. If you are programming a computer you are making the computer do a desired task. 
7 0
3 years ago
Other questions:
  • Janice has a "jammed" key on her keyboard. Every time she strikes the "S" key it sticks and doesn't pop back. What should Janice
    6·2 answers
  • How to remove a channel from favorite list on suddenlink?
    15·1 answer
  • What systemctl command configures a unit to start the next time the computer boots?
    10·1 answer
  • You have just changed the system time within your computer's BIOS. You choose to save the settings upon exit. What happens next
    14·2 answers
  • Which of the following is NOT a fall prevention system?
    12·2 answers
  • What are the benefits of writing functions that use parameters and return? Try to list at least two.
    12·1 answer
  • 10010 - 1011 binary subtraction​
    5·1 answer
  • Which of these are characteristics of a Python data type? Check all that apply.
    11·1 answer
  • Which factor affects reading speed the most?
    9·1 answer
  • Choose the answer.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!