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

who had the most victories in the first years of the civil war
Select the correct answer. Both bacteria and amoeba are unicellular organisms. Bacteria are considered to be prokaryotes, whereas amoebas are considered to be e
143 x 2 Pls help me please
why the battle of Stalingrad was a turning point in the war on Europe
John Smith leaves his job in New York to go to California in hopes of finding a better one. If John Smith is unemployed while searching for a job in​ California
During a criminal trial process, whom does the jury inform after arriving at a verdict?
The Battle of _______ forced the British to surrender, ending the Revolutionary War.
What is X = to in -3x+4x=2•4-x​
What is anectodal evidence?
• Lasting peace in the post-World War I world • Rights for all countries to choose their own governing systems • A League of Nations to discuss and resolve inte