Question

Run the below code and shift binary left and right and understand the output. #include <stdio.h>...

Run the below code and shift binary left and right and understand the output.

#include <stdio.h>

int main()

{

    int num=212, i;

    for (i=0; i<=2; i++)

        printf("Right shift by %d: %d\n", i, num>>i);

     printf("\n");

     for (i=0; i<=2; i++)

        printf("Left shift by %d: %d\n", i, num<<i);   

   

     return 0;

}

Output:

Homework Answers

Answer #1

Output :

Right shift by 0: 212
Right shift by 1: 106
Right shift by 2: 53

Left shift by 0: 212
Left shift by 1: 424
Left shift by 2: 848

Explanation :

At first the for loop will iterates from the 0 to 2:

At first i = 0

num >> i = 212 >> 0 (212 / 20)

= 212

i = 1 :

num >> i = 212 >> 1 (212 / 21)

= 106

i = 2 :

num >> i = 212 >> 2 (212 / 22)

= 53

The second loop will starts executing from i = 0 to 2 (Left shift operations)

At first i = 0

num >> i = 212 >> 0 (212 * 20)

= 212

i = 1 :

num >> i = 212 >> 1 (212 * 21)

= 424

i = 2 :

num >> i = 212 >> 2 (212 * 22)

= 8484

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What would appear in the console window after the code below executes? #include <stdio.h> int main()...
What would appear in the console window after the code below executes? #include <stdio.h> int main() { char myLetter = 'A'; printf("The value of A is %d", myLetter); }
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL && pointVar2 == NULL) {       printf("Pointer is null\n");    }    else if (*pointVar2 > *pointVar1) {       printf("%p\n", *pointVar2);    }    else if (*pointVar1 > *pointVar2) {       printf("%p\n", *pointVar1);    } } int main() {    int num1 = 5;    int num2 = 9;       CheckValue(&num1, &num2);           return 0; } a. 0 b. 5 c. 9 d. Pointer is null e....
Compile and run the following code and presuming your executable is in a.out, run this command...
Compile and run the following code and presuming your executable is in a.out, run this command from the shell prompt: ./a.out ; echo "Parent Terminated Normally with a return value of $?" Explain, in your own words, why you see the screen output you do and how that output relates to both the content of the program AND the nature of the shell command used to invoke it. Hint: This has everything to do with how processes “communicate” their exit...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char *b[]) { 6 int c = atoi(a[0]); 7 for (int i = 0; i < c && b[i]; ++i) { 8 printf("%s", b[i]+2); 9 } 10 } 11 12 void main(int argc, char *argv[]) { 13      14 switch (argc) { 15 case 1: 16 for (int i = 0; environ[i]; ++i) {    17 printf("%s\n", environ[i]); 18 } 19 break; 20 default: 21 output(argv +...
2. Calculate number of times hello is printed. #include <stdio.h> #include <sys/types.h> int main() { fork();...
2. Calculate number of times hello is printed. #include <stdio.h> #include <sys/types.h> int main() { fork(); fork(); fork(); printf("hello\n"); return 0; }
How can i make this lunix code print 3 numbers in reverse it must be in...
How can i make this lunix code print 3 numbers in reverse it must be in printStars format and no loops Here is the code i have but can figure out how to reverse the numbers #include<stdio.h> void printStars(int n) { if (n>0){ printf(""); printStars(n-1); } } int main() { int n; int b; int c; printf("Enter 3 numbers to reverse "); scanf("%d",&n,&b,&c); printf("your reversed numbers are %d",n); printStars(n); return 0;
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25...
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25 points) // Note: You may notice some warnings for variables when you compile in GCC, that is okay. #define macro_1(x) ((x > 0) ? x : 0) #define macro_2(a, b) (3*a - 3*b*b + 4*a * b - a*b * 10) int function_1(int a, int b) { return (3*a - 3*b*b + 4*a * b - a*b * 10); } // Part 1: //...
C CODE PLZ! All instructions are in sections of code #include <stdio.h> /* TODO: Define 3...
C CODE PLZ! All instructions are in sections of code #include <stdio.h> /* TODO: Define 3 functions input, gcd and lcm in such a way that the main function below compiles correctly and has the correct behavior. The input function prompts the user to enter a non-negative integer. If the user enters a negative integer, the function prints a "sorry" statement and prompts the user again. It keeps on prompting until the user enters a non-negative number. The input function...
LANGUAGE C The codes below reads another .c or .txt file. Then, it will read the...
LANGUAGE C The codes below reads another .c or .txt file. Then, it will read the contents of every line and store the contents into a string array. Example: .c file that is to be read: #include <stdio.h> int main(){    printf("Hello World");    return ; } _______________(END OF THE FILE)_______________ Therefore, the code will read the contents above and store the contents in every line into an array, such that.... array[0] = "#include <stdio.h>\n" array[1] = "\n" array[2] ="int...
q : explain the code for a beginner in c what each line do Question 2....
q : explain the code for a beginner in c what each line do Question 2. The following code defines an array size that sums elements of the defined array through the loop. Analyze the following code, and demonstrate the type of error if found? What we can do to make this code function correctly ? #include <stdio.h> #define A 10 int main(int argc, char** argv) { int Total = 0; int numbers[A]; for (int i=0; i < A; i++)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT