Question: C PROGRAM i need exact output A21 - WAP to implement Circular left shift Description: Read a number num from user. Read a number n

C PROGRAM i need exact output

A21 - WAP to implement Circular left shift

Description:

Read a number num from user.

Read a number n from user.

Pass num and n to the function.

Shift num, n times (towards left).

While shifting the shifted bits should get replaced at the alternate end.

For left shifting, the shifted bits should come at right most side.

Return the new number from the function.

Print the new number.

Example:

If num is -2, and n is 3, in circular_left_shift function 12 -> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 o/p -> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1

Pr-requisites:-

Bitwise Operators

Type Modifiers

Functions

Objective: -

To understand the concept of

Functions

Bitwise Operators

Inputs: -

Integers num(both +ve and -ve), n(No.of shifts)

Sample execution: - Test Case 1: user@emertxe] ./bit_ops

Enter num: 12 Enter n : 3 Result in Binary: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0

Test Case 2: Enter num: -2 Enter n : 3 Result in Binary: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1

requested files;

#include

int circular_left(int, int); int print_bits(int);

int main() { int num, n, ret; printf("Enter the num:"); scanf("%d", &num); printf("Enter n:"); scanf("%d", &n); ret = circular_left(num, n); print_bits(ret); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!