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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started