Question
follow direction C language For this section of the lab, make a file called baseConv.c. In it, you are to first create two functions that
follow direction
C language
For this section of the lab, make a file called baseConv.c. In it, you are to first create two functions that perform binary to decimal conversion and back. Their signatures should look like:
int binToDec(char* bin);
char* decToBin(int dec);
That is, the binary numbers will be represented by a "string" of 0s and 1s. So you might call the first method using something like:
int num = binToDec("11001");
The best way to test is to run one method and then take the results and run it through the other method. So "11001" should result in 25, and 25 should result in "11001".
Once you have tested that your code works for both methods, you should then make a copy of your methods and upgrade them to do any base conversion to decimal and back. Those signatures should look like:
int baseToDec(int base, char* value);
char* decToBase(int base, int dec);
Example calls would be:
int dec = baseToDec(2, "11001");
int dec = baseToDec(8, "157");
int dec = baseToDec(16, "f8");
Try to make as little changes to your code as possible. Look at what you can generalize when modifying the base 2 only code. You code should work for any base from 2 up to 16. But please do not code every possible case individually! However, having two cases to handle letters (A-F) vs numbers (0-9) is okay.
BitSet
Make a file called bitset.c It should have a main as well as several functions that operate on bitsets. You should include the following typedef:
typedef unsigned short bitSet;
And the following functions:
bitSet makeBitSet(); // Create a new bitset
displayBitSet(bitSet bs); // Displays the 16 bits of the bitset to the screen
void setBit(bitSet* bs, int index); // Sets bit 'index' of the bitset to 1
void clearBit(bitSet* bs, int index); // Sets bit 'index' of the bitset to 0
int bitValue(bitSet bs, int index); // Returns the value of the bit at 'index'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started