Can someone help me with this? I dont understand what they are asking for. So if somone could maby do the first exersice or something, that would mean the world to me :)!
Write a small library that has the following functions:
byte setBit(byte b, byte bitnum);
- Take the byte b and set bit number bitnum to 1. Return the result.
byte clrBit(byte b, byte bitnum);
- Take the byte b and clear bit number bitnum. Return the result.
byte getBit(byte b, byte bitnum);
- Take the byte b and return the value of bitnum .
byte flpBit(byte b, byte bitnum);
- Take the byte b and flip bit number bitnum (0 -> 1, 1 -> 0). Return the result.
byte getLoNibble(byte b);
- Return the least significant nibble1
of the byte b.
byte getHiNibble(byte b);
- Return the most significant nibble of the byte b.
byte bitrotL(byte b);
- Rotate the byte b to the left one position. Return the result.
byte bitrotR(byte b);
- Rotate the byte b to the right one position. Return the result.
char * bitStr(byte b);
- Take the byte b and convert it to an 8 character long text string.
Example: b=161 --> “10100001”. Hint: Use the hexit tool to check the output.
You may use functions from the stdlib, string, stdio libraries as needed.
Requirements:
Define the type «byte» to be an 8 bit unsigned integer using a typedef declaration.
Use assert() statements to verify that the input to the functions are within the correct
ranges. Also check all output values.
o Range for bitnum: [0..7]
The small library shall be contained within a separate compilation unit. That is, a separate C
file with an associated header file.
Write a test program that checks boundaries for the input variables for all functions. Check
also all output.