Question: C: Create a header file named binary _ string.h . The header file should declare the following three functions: char * unsigned _ to _

C:
Create a header file named binary_string.h. The header file should declare the following three functions:
char* unsigned_to_binary(unsigned x);
unsigned binary_to_unsigned(char* str);
char* add_binary(char* str1, char* str2);
Be sure to include a header guard.
Write a C program named binary_string.c. That program should implement the following three functions:
char* unsigned_to_binary(unsigned x)
unsigned_to_binary() takes an unsigned number and returns a c-style string of '0' and '1' characters that represents the binary representation of the argument. For example, unsigned_to_binary(13) should return a pointer to a char array containing {'1','1','0','1','\0'} and unsigned_to_binary(257) should return a pointer to a char array containing {'1','0','0','0','0','0','0','0','1','\0'}. Notice it stores only as many "bits" as necessary (you can assume a max of 32 bits (plus the null character '\0')). Note: unsigned_to_binary() should call malloc() to allocate enough space for the chars.
unsigned binary_to_unsigned(char* str)
binary_to_unsigned() takes a pointer to a c-style string that holds a sequence of '0' and '1' characters and returns the unsigned representation.
char* add_binary(char* str1, char* str2)
add_binary() takes two char* c-style binary strings and returns the sum as a binary string. You should not use the functions from the previous parts here. However, if you have helper functions that you wish to reuse, you may do so, so long as they are in the spirit of what this task is asking you to do.
Add the "bits" from least significant to most significant, "carrying the one" when necessary. (You can again assume a max size of 32 bits. You should discard the overflow bit if the addition exceeds this max size.)
So, if your helper functions (say) convert the entire string to numbers, add them, and turn the entire number back into one string, that does not count as solving this problem. Helper functions that do something useful in the spirit of the task (like, say, counting the digits of a c-style string) would be fine and even encouraged.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!