subject

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");

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:00
Which of the following is a way that advancements in technology improve humans' ability to measure air quality and protect human health? a. air quality data gathered by new instruments can be used to reduce exposure to pollutants. b. new technologies enable natural and human-made pollution sources to be located and monitored. c. air quality data gathered by new instruments can be used to predict trends in pollution over time. d. new technologies allow governments to make informed decisions about the regulation of pollution. (choose more than one)
Answers: 2
question
Computers and Technology, 23.06.2019 05:30
Sally is editing her science report about living things. she needs to copy a paragraph from her original report. order the steps sally needs to do to copy the text to her new document.
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
This question involves a class named textfile that represents a text file. public class textfile { private string filename; private string filename; private arraylist words; // constructors not shown // postcondition: returns the number of bytes in this file public int filesize() { } // precondition: 0 < = index < words.size() // postcondition: removes numwords words from the words arraylist beginning at // index. public void deletewords(int index, int numwords) { } // precondition: 0 < = index < = words.size() // postcondition: adds elements from newwords array to words arraylist beginning // at index. pub lic voidaddwords(int index, string[] newwords) { } // other methods not shown } complete the filesize() method. the filesize() is computed in bytes. in a text file, each character in each word counts as one byte. in addition, there is a space in between each word in the words arraylist, and each of those spaces also counts as one byte. for example, suppose the words arraylist stores the following words: { mary had a little lamb; its fleece was white as snow. } the filesize() method would compute 4 + 3 + 1 + 6 + 5 + 4 + 6 + 3 + 5 + 2 + 5 as the sum of the lengths of each string in the arraylist. the value returned would be this sum plus 10, because there would also be 10 spaces in between the 11 words. complete the filesize() method below: // postcondition: returns the number of bytes in this file public int filesize() { }
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
Simon says is a memory game where "simon" outputs a sequence of 10 characters (r, g, b, y) and the user must repeat the sequence. create a for loop that compares the two strings. for each match, add one point to user_score. upon a mismatch, end the game. sample output with inputs: 'rrgbryybgy' 'rrgbbrybgy'
Answers: 3
You know the right answer?
In this assignment, you will write a program that will contain two functions, setlsbs() and getlsbs(...
Questions
question
Biology, 01.12.2020 04:00
question
Social Studies, 01.12.2020 04:00
question
Mathematics, 01.12.2020 04:00
question
Chemistry, 01.12.2020 04:00
Questions on the website: 13722360