Computers and Technology

In this assignment, you will write a program that will contain two functions, setlsbs() and getlsbs(). These functions will use bitwise operators to embed and extract "hidden" bits in a character array.

Specifications:
Your first function:

void setlsbs(unsigned char *p, unsigned char b0)

will take as parameters, an array p of eight bytes (unsigned char) and a byte byte0. It will replace the least significant bits (LSBs) of p by the bits of byte0. In other words, if the binary representation of byte0 is b7b6b5b4b3b2b1b0, you should replace the LSB of p[0] by b0, the LSB of p[1] by b1, ... , and the LSB of p[7] by b7.

Your second function:

unsigned char getlsbs(unsigned char *p)

will take an array p of eight bytes (unsigned char) and return a byte byte0 which is created by combining the LSBs of p. That is, your function should combine the least significant bits bi of p[i] to return a byte b7b6b5b4b3b2b1b0.

Write a program to test your functions as follows:

Obtain a random number seed from the command line of your program using command line arguments.

Initialize an array p of 8 unsigned char with random numbers from 0 to 255

Initialize a separate unsigned character byte0 with a random number.

Print the values in the array p as well as the value for byte0.

Print the values in decimal format as well as binary format (use macros defined below)

Call setlsbs() using p and byte0 as parameters

After the call to setlsbs() is completed, print the modified values of the array p.

Print the values in decimal format as well as binary format (use macros defined below)

Use the modified array p as a parameter to getlsbs()

Print the return value of the call to getlsbs(). The returned value should match the original value for byte0

Print the value in decimal format as well as binary format (use macros defined below)

You will create a Makefile to compile and link your programs.

Macros:
You may use the following macros to print the binary representation of unsigned character variables:

#define BYTETOBINARYPATTERN "%d%d%d%d%d%d%d%d"

#define BYTETOBINARY(byte) \
(byte & 0x80 ? 1 : 0), \
(byte & 0x40 ? 1 : 0), \
(byte & 0x20 ? 1 : 0), \
(byte & 0x10 ? 1 : 0), \
(byte & 0x08 ? 1 : 0), \
(byte & 0x04 ? 1 : 0), \
(byte & 0x02 ? 1 : 0), \
(byte & 0x01 ? 1 : 0)

#define PRINTBIN(x) printf(BYTETOBINARYPATTERN, BYTETOBINARY(x));

You can use the macros in a manner similar to the code below:

unsigned char num =173;

PRINTBIN(num); printf("\n");

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 09:50, tatumleigh04
Allison and her group have completed the data entry for their spreadsheet project. they are in the process of formatting the data to make it easier to read and understand. the title is located in cell a5. the group has decided to merge cells a3: a7 to attempt to center the title over the data. after the merge, allison points out that it is not centered and looks bad. where would the title appear if allison unmerged the cells in an attempt to fix the title problem?
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, larry5007
Freya realizes she does not have enough in her bank account to use the debit card. she decides to use a credit card instead. which questions should freya answer before using a credit card? check all that apply. can i pay at least the minimum payment each month? can i make payments on time and avoid late fees? will i have to take out a loan? how much in finance charges can i afford to pay? should i talk to a consumer credit counseling service?
Answers: 1
image
Computers and Technology, 24.06.2019 18:30, txa95
After making a powerpoint presentation about a new line of clothing designs, henri notices that he used the word “gorgeous” on nearly every slide. what would be the  best  way to add more variety to his wording by using tools within powerpoint? using the thesaurus under the view tab, and then using the find dialog box to find and replace every instance of “gorgeous”using the spelling checker under the view tab, and then using the find dialog box to find every instance of “gorgeous” and change some of themusing the thesaurus under the review tab, and then using the find dialog box to find every instance of “gorgeous” and change some of themusing the spelling checker under the review tab, and then using the find dialog box to find and replace every instance of “gorgeous”
Answers: 2
image
Computers and Technology, 24.06.2019 20:30, jalenevoyles
Which key should you press to leave the cell as it originally was? a. delete b. cancel c. backspace d. enter
Answers: 1
Do you know the correct answer?
In this assignment, you will write a program that will contain two functions, setlsbs() and getlsbs(...

Questions in other subjects:

Konu
Mathematics, 03.07.2019 00:30
Konu
Social Studies, 03.07.2019 00:30