![Tringirl233](/avatars/3261.jpg)
Tringirl233
08.03.2021 •
Computers and Technology
Write a C program that reads a hexadecimal value from the keyboard and then stores the value into an unsigned char variable. Read two int values p and n from the keyboard, where the values are less than 8. Change the initial hexadecimal value in the following way: Shift the n bits starting at position p, so that they form the n least significant bits of the result. The remaining bits of the result are set to 0. Display the result using printf %x.
Solved
Show answers
More tips
- H Health and Medicine How to Whiten Teeth and Get the Perfect Smile...
- F Food and Cooking How to Make Thin Pancakes: Recipe and Tips...
- S Style and Beauty Is Hot Scissor Haircutting Beneficial or Dangerous?...
- S Style and Beauty How to Get Rid of Under Eye Bruises?...
- F Food and Cooking Is Bacon Good for You?...
- S Style and Beauty Discover the Art of Nail Design: How Do You Paint Your Nails?...
- P Philosophy How to Develop Extrasensory Abilities?...
- O Other Everything You Need to Know About Kudyabliks...
- C Computers and Internet The Twitter Phenomenon: What it is and How to Use it...
- C Computers and Internet How to Choose a Laptop: Expert Guide and Tips...
Answers on questions: Computers and Technology
- C Computers and Technology Eight-queen s problem Consider the classic puzzle of placing eight queens on an 8 x 8 chessboard so that no two queens are in the same row or in the same column or on the same diagonal....
- M Mathematics What is x in -2/3x - 11 = -7...
- M Mathematics How do you simplify 65/100?...
- E English 5 sentences on respect...
- M Mathematics I need help on this equation 6s-10=s...
- M Mathematics How many times can 14 go into 21...
- M Mathematics What is this opposite of -5.6 ?...
- M Mathematics Is 8+y=4x a linear equation?...
- M Mathematics Kyle is planning to hike a trail that is 24 miles long. He hikes at a rate of 6 mi/hr. Write a lineup equation in slope intercept form to represent the distance y, Kyle has remaining...
- M Mathematics Dan invests £800 into his bank account. He receives 5% per year compound interest. How much will Dan have after 4 years? Give your answer to the nearest penny where appropriate....
Ответ:
#include<stdio.h>
int main(){
unsigned char var;
int p,n;
printf("a: ");
scanf("%x",&var);
printf("p: ");
scanf("%d",&p);
printf("n: ");
scanf("%d",&n);
while(1){
char command;
scanf("%c",&command);
if(command=='S'){
var=var | (((1<<n)-1)<<(p-1));
} else if(command=='R'){
var=var & ~(((1<<n)-1)<<(p-1));
} else if(command=='F'){
var=var ^ (((1<<n)-1)<<(p-1));
} else if(command=='D'){
printf("a = %02x H : ",var);
int i;
for(i=7;i>=4;i--){
printf("%d",((1<<i)&(var))>>i);
printf(" ");
for(i=3;i>=0;i--){
printf("%d",((1<<i)&(var))>>i);
printf(" B\n");
}
}
} else if(command=='I'){
printf("a = ");
scanf("%x",&var);
}
}
}
Explanation:
The C source code gets user inputs from a keyboard as integer numbers, p and n, which is converted to binary (8 bits of one and zero value) as the memory for the input hexadecimal number and character values are also inputs from the keyboard, used as flags to determine the way the hexadecimal number is stored or displayed.
Ответ:
The younger people or other villages may realize the wrong. If other villages stop, the chain will continue ending the lottery.