###### Programming-for-Output-Problems

October 6, 2023###### Programming-for-Output-Problems

October 6, 2023# Programming-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)

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)

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)

= (2700)

(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)

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)

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)

= (2700)

(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