Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function that begins: int rotate_left (unsigned num, int n) { This function should left-shift num by n positions, where the high-order bits are

Write a function that begins: int rotate_left (unsigned num, int n) { This function should left-shift num by n positions, where the high-order bits are reintroduced as the low-order bits. Here are two examples of a circular shift operation using a short bit pattern, rather than a full integer. 1000 0001 circular shift 1 yields 0000 0011 0110 1011 circular shift 3 yields 0101 1011

image text in transcribedimage text in transcribed

THIS IS THE GIVEN SHELL

#include

#include

/* function prototypes */

void bitprint (unsigned num);

int rotate_left(unsigned num, int n);

/*-----------------------------------------*/

int main (void)

{

int left_count;

unsigned num; /* the starting number */

unsigned shifted_num;

printf(" Your Name. Lab 8. ");

do

{

/* read a unsigned integer */

printf(" Enter an unsigned integer value (0 to stop): ");

scanf("%u", &num);

if (num != 0)

{

printf(" Enter an integer value for the left shift: ");

scanf("%d", &left_count);

printf(" Original is %i ", num);

bitprint(num);

shifted_num = rotate_left(num, left_count);

bitprint(shifted_num);

printf("Shifted it is %i ", shifted_num);

}

} while (num != 0);

printf(" ");

return EXIT_SUCCESS;

}

/*--------------------------------------------------------------*/

void bitprint (unsigned num)

{

unsigned mask;

int bit, count, nbits;

/* determine the word size in bits and set the initial mask */

nbits = 8 * sizeof(unsigned); /* finds number of bytes in an unsigned

number and changes it to bits */

mask = 0x1

starting place for the mask */

for(count = 1; count

{

bit = (num & mask) ? 1: 0; /* set display bit on or off */

printf("%x", bit); /* print display bit */

if(count %4 == 0)

printf(" "); /* blank space after every 4th digit */

mask >>= 1; /* shift mask 1 position to the right */

}

printf(" ");

return;

}

/*--------------------------------------------------------------*/

int rotate_left(unsigned num, int n)

{

{

int count, bit, nbits;

unsigned mask;

nbits = 8 * sizeof(unsigned); /* finds number of bytes in an int

unsigned number and changes it to bits */

mask = 0x1

starting place for the mask */

// put the loop here and then the return

INPUT/OUTPUT DESCRIPTION: The input: in a loop, request two unsigned numbers. The output is printed to the screen by main. A SAMPLE RUN: Your Name. Lab 8. Enter an unsigned integer value (0 to stop) : 3 Enter an integer value for the left shift: 4 Original is 3 0000 0000 0000 0000 0000 0000 0000 0011 0000 0000 0000 0000 0000 0000 0011 0000 Shifted it is 48 Enter an unsigned integer value (0 to stop) : 5 Enter an integer value for the left shift: 3 Original is 5 0000 0000 0000 0000 0000 0000 0000 0101 0000 0000 0000 0000 0000 0000 0010 1000 Shifted it is 40 Enter an unsigned integer value (0 to stop) : 0

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_2

Step: 3

blur-text-image_3

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago

Question

The company has fair promotion/advancement policies.

Answered: 1 week ago