dragonffkc8757 dragonffkc8757
  • 02-05-2021
  • Computers and Technology
contestada

Write a C program that right shifts an integer variable 4 bits. The program should print the integer in bits before and after the shift operation. Does your system place 0s or 1s in the vacated bits?

Respuesta :

AbsorbingMan AbsorbingMan
  • 03-05-2021

Solution :

#include<[tex]$\text{stdio.h}$[/tex]>

#include<conio.h>

void dec_bin(int number) {

[tex]$\text{int x, y}$[/tex];

x = y = 0;

for(y = 15; y >= 0; y--) {

x = number / (1 << y);

number = number - x * (1 << y);

printf("%d", x);

}

printf("\n");

}

int main()

{

int k;

printf("Enter No u wanted to right shift by 4 : ");

scanf("%d",&k);

dec_bin(k);

k = k>>4; // right shift here.

dec_bin(k);

getch();

return 0;

}

Answer Link

Otras preguntas

How does transpiration play a  role in the water cycle ?
A passenger on a boat moving at 1.70 m/s on a still lake walks up a flight of stairs at a speed of 0.60 m/s , as shown in the figure . The stairs are angled at
is it possible for a distance versus-time graph to be a vertical line?
If the speed of an object is tripled, its kinetic energy will be
You have a cylinder with a diameter of 15 inches and a height of 12 inches. What is the volume of the largest sphere thg will fit inside it? If you can will you
is it possible for a distance versus-time graph to be a vertical line?
When was William Shakespeare born
You have a cylinder with a diameter of 15 inches and a height of 12 inches. What is the volume of the largest sphere thg will fit inside it? If you can will you
What are two different ways to describe and label the layers of the Earth?
Can u paraphrase the quote ”let things take their course”