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]
2 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]2 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 an application that determines which, if any, of the following files are stored in the folder where you have saved the exe
Elza [17]

Answer:

Here is the JAVA application that determines which if any of the following files are stored in folder where you have saved the exercises created.

import java.nio.file.*;   // used to manipulate files and directories

import java.nio.file.attribute.*;  //used to provide access to file and file attributes

import static java.nio.file.AccessMode.*;  // provides access modes to test the accessibility of a file

import java.io.IOException;  //for exception handling

class FindSelectedFiles {

public static void main(String[] args) { //start of main function

   Path f1 = Paths.get("/root/sandbox/autoexec.bat"); //creates Path object f1 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f2 = Paths.get("/root/sandbox/CompareFolders.java");  //creates Path object f2 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f3 = Paths.get("/root/sandbox/FileStatistics.class");   //creates Path object f3 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f4 = Paths.get("/root/sandbox/Hello.doc"); //creates Path object f4 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   int count=0; //used to count the number of files found  

try{  // used to define a code chunk to be tested for errors

 f1 = Paths.get("/root/sandbox/autoexec.bat");  // Converts a path string when joined form a path string to a Path

 System.out.println(f1);  //prints the file

     /* getFileSystem method is used to return the file system that created this Path object f1 and checkAccess Verifies access and throws exception if something is wrong

 f1.getFileSystem().provider().checkAccess(f1);  

 System.out.println(f1 +" File Exists\n");  //if file exists then displays this message

 count++;  }  //adds 1 to the count of number of files found

 catch (IOException e) {  //a code chunk to be executed if error occurs in the try part

  System.out.println("File Doesn't Exist\n"); }  //if file not found displays this message

   

try{  //works same as above try block but for 2nd folder and object f2

 f2 = Paths.get("/root/sandbox/CompareFolders.java");

 System.out.println(f2);

 f2.getFileSystem().provider().checkAccess(f2);

 System.out.println(f2 +" File Exists\n");

 count++;  }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

try{  //works same as above try block but for 3rd folder and object f3

 f3 = Paths.get("/root/sandbox/FileStatistics.class");

 System.out.println(f3);

 f3.getFileSystem().provider().checkAccess(f3);

 System.out.println("File Exists\n");

 count++; }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

try{  //works same as above try block but for 4th folder and object f4

    f4 = Paths.get("/root/sandbox/Hello.doc");

    System.out.println(f4);

 f4.getFileSystem().provider().checkAccess(f4);

 System.out.println(f4 +" File Exists\n");

 count++; }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

   System.out.println(count+" of the files exist");  }  } //displays the number of files found

Explanation:

If you want to directly pass the file name as argument to Paths.get() method then you can use the following code:

   Path f1 = Paths.get("autoexec.bat");

   Path f2 = Paths.get("CompareFolders.java");

   Path f3 = Paths.get("FileStatistics.class");

   Path f4 = Paths.get("Hello.doc");

The program determines if any, of the files from autoexec.bat, CompareFolders.java, FileStatistics.class, and Hello.doc. are stored in the folder. If a file is found then the program displays the message File exists and add 1 to the count variable each time a file is found. If all the files are found then the program returns the count as 4 otherwise the program display the number of files found by displaying the computed final value of count in the output. Lets say all the files are found then the output of the above program is:

autoexec.bat                                                                                                                                                   autoexec.bat File Exists  

                                                                                                                                                      CompareFolders.java                                                                                                                                            CompareFolders.java File Exists                                                      

                                                                                                                                                         FileStatistics.class                                                                                                                                           File Exists                                                                                        

                                                                                                                                                     Hello.doc                                                                                                                                                      Hello.doc File Exists  

   

4 of the files exist    

8 0
2 years ago
write a program to update the rate by increasing 20% from sequential data file "items.dat" that store item name.rate and quantit
sveticcg [70]

Answer:

your answer is in the pic

(◔‿◔)

。◕‿◕。

6 0
2 years ago
If a user wants to add an expansion card to increase the memory of a computer, where should the user insert the card?
uysha [10]

into a port on the outside of the computer


6 0
2 years ago
Read 2 more answers
Which two statements describe features of an ipv4 routing table on a router? (choose two.)
solong [7]

The statements that describe features of an ipv4 routing table on a router include:

  • Directly connected interfaces will have two route source codes in the routing table.
  • If a default static route is configured in the router, an entry will be included in the routing table with source code.

It should be noted that the IPv4 route table is important for listing entries that are in the routing table.

The routing table of every router is unique and can be stored in the read access memory (RAM) of the device.

Read related link on:

brainly.com/question/24958077

7 0
2 years ago
The procedure by which a process's state is saved before being swapped out of the cpu, then us restored to the state when the pr
belka [17]

The procedure is known as<u> context switching</u>.

In the field of computers, context switching can be described as a procedure in which a process is stored so that it can be executed at a later point. Such a procedure allows multitasking operations easier. A simple CPU can be utilized for multiple processes.

After a task is done, it can be swapped out of the CPU and can be restored later. By using context switching, more space can be provided on a CPU as freeing from one process will make space for the other.

When switching a process, the status of the older running process is saved on the CPU as registers.

Context switch makes it feasible to share one CPU for multiple procedures hence reducing the concerns that arise from using additional processors.

To learn more about context switch, click here,

brainly.com/question/21685677

#SPJ4

3 0
1 year ago
Other questions:
  • I NEED HELP NOW PLEASE!!!!!!
    6·2 answers
  • A(n) ________ software installation enables you to decide which features you want to install on the hard drive. Select one: A. f
    10·1 answer
  • An administrator running a port scan wants to ensure that no processes are listening on port 23. What state should the port be i
    7·1 answer
  • Which note-taking method quickly captures and organizes information?
    9·2 answers
  • ) Which is true about the agile method?
    7·1 answer
  • In this scenario, hackers launch cyber-attacks that affect several parts of the nationâs financial infrastructure over the cours
    8·1 answer
  • Your sister asks you if it is possible to get an office productivity suite for free. What do you tell her?
    13·1 answer
  • Determining the Services Running on a Network Alexander Rocco Corporation has multiple OSs running in its many branch offices. B
    10·1 answer
  • What is the first step a user should take toward generating an index?
    7·1 answer
  • Adam has designed and tested an Android app for a startup. The client expects to get quick responses to the app. After consultin
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!