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

Round 5.928301 to 2 decimal places
$11.20 is 30% of what number???
hulk left home and walked 8 blocks west. then he turned and walked 6 blocks north. if each block is 500 ft long how far is hulk from home
what might a tyrant say to a citizen who are asking for democracy
Which of the following uses a nonrenewable energy resource to generate energy? A. nuclear power plant B. wind farm C. fireplace that burns wood D.
lexema y sufijo de papeleria
Grace bought 4.5 pounds of fish that cost $4.98 per pound. how much did she pay for fish?
The average of two numbers is 25 and their difference is 8. What are the numbers?
4.   The largest proportion of federal revenues comes from      A. excise taxes.B. personal income taxes.C. borrowing.D. social insurance taxes.
what is the legislative body called