Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
Question 7
|
Write the output of the following C program
#include <stdio.h>
int main (void)
{
int shifty;
shifty = 0570;
shifty = shifty >>4;
shifty = shifty <<6;
printf(“the value of shifty is %o”,shifty);
}
#include <stdio.h>
int main (void)
{
int shifty;
shifty = 0570;
shifty = shifty >>4;
shifty = shifty <<6;
printf(“the value of shifty is %o”,shifty);
}
the value of shifty is 1500
|
|
the value of shifty is 4300
|
|
the value of shifty is 5700
|
|
the value of shifty is 2700
|
Question 7 Explanation:
Given, shifty = 0570; // number starts with 0 means that number is octal number.
(0570)8 = (000 101 111 000)2 (Converting octal number into binary number)
shifty = shifty >>4 ( >> right shift operator where we need to shift the 4 bits towards right side means discard last four bits )
After right shifting 4 bits the shifty consists of the following digits
shifty = (000 000 010 111) 2
shifty = shifty <<6( << left shift operator where we need to shift the 6 bits towards left side means add si bits to the end of the binary number. So the binary number becomes as follows
shifty = (010 111 000 000) 2
= (2700) 8
(0570)8 = (000 101 111 000)2 (Converting octal number into binary number)
shifty = shifty >>4 ( >> right shift operator where we need to shift the 4 bits towards right side means discard last four bits )
After right shifting 4 bits the shifty consists of the following digits
shifty = (000 000 010 111) 2
shifty = shifty <<6( << left shift operator where we need to shift the 6 bits towards left side means add si bits to the end of the binary number. So the binary number becomes as follows
shifty = (010 111 000 000) 2
= (2700) 8
Correct Answer: D
Question 7 Explanation:
Given, shifty = 0570; // number starts with 0 means that number is octal number.
(0570)8 = (000 101 111 000)2 (Converting octal number into binary number)
shifty = shifty >>4 ( >> right shift operator where we need to shift the 4 bits towards right side means discard last four bits )
After right shifting 4 bits the shifty consists of the following digits
shifty = (000 000 010 111) 2
shifty = shifty <<6( << left shift operator where we need to shift the 6 bits towards left side means add si bits to the end of the binary number. So the binary number becomes as follows
shifty = (010 111 000 000) 2
= (2700) 8
(0570)8 = (000 101 111 000)2 (Converting octal number into binary number)
shifty = shifty >>4 ( >> right shift operator where we need to shift the 4 bits towards right side means discard last four bits )
After right shifting 4 bits the shifty consists of the following digits
shifty = (000 000 010 111) 2
shifty = shifty <<6( << left shift operator where we need to shift the 6 bits towards left side means add si bits to the end of the binary number. So the binary number becomes as follows
shifty = (010 111 000 000) 2
= (2700) 8
Subscribe
Login
0 Comments