Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description : In this lab you will write a program in C that will contain two functions, setlsbs () and getlsbs (). These functions will

Description: In this lab you will write a program in C 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 isb7b6b5b4b3b2b1b0, 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 byteb7b6b5b4b3b2b1b0.

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)

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

What was the role of the team leader? How was he or she selected?

Answered: 1 week ago

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago