subject

Objectives: number system, bitwise operations, masking. main() function: 1. declare an int variable, name it number. 2. prompt the user to enter a whole number – read it into the variable. • validate the range in a loop. valid range is 20 to 200 both inclusive 3. display the number to the screen (base 10) 4. display the number in hexadecimal (use %x) 5. determine the rightmost bit in the number, display it to the screen (0 or 1): • int maskright = 1; // 0001 • do a bitwise & between the number and the maskright. if it is equal to 0, the rightmost bit is 0, otherwise, it is 1. 6. determine the third bit from the right in the number • int mask3rd = 4; // 0100 • do a bitwise & between the number and mask3rd – if it is equal to 0 the 3rd bit in the number is 0, otherwise it is 1. 7. display the number in 16 bit binary as follows: • define a mask = 1 < < 15; // 1000• write a loop that iterates 16 times. in each cycle: i. do a bitwise & between the mask and the number (in an if statement). ii. display the corresponding bit (0 or 1) iii. shift the mask to the right one bit for the next cycle. iv. if the loop variable is divisible by 4 print a space " ". 8. shift the number to the left by 2 bits – display the updated number to the screen (it will be multiplied by 2 twice).

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:00
Ulia is planning to attend the same private four-year college her parents attended. she wants to save at least $18,000 in four years to contribute to her college education. which monthly deposit amounts can julia use to achieve her goal? check all that apply.
Answers: 2
question
Computers and Technology, 22.06.2019 22:40
When you type the pwd command, you notice that your current location on the linux filesystem is the /usr/local directory. answer the following questions, assuming that your current directory is /usr/local for each question. a. which command could you use to change to the /usr directory using an absolute pathname? b. which command could you use to change to the /usr directory using a relative pathname? c. which command could you use to change to the /usr/local/share/info directory using an absolute pathname? d. which command could you use to change to the /usr/local/share/info directory using a relative pathname? e. which command could you use to change to the /etc directory using an absolute pathname? f. which command could you use to change to the /etc directory using a relative pathname?
Answers: 3
question
Computers and Technology, 23.06.2019 05:00
Which best explains why a digital leader would join a society specializing in technology
Answers: 1
question
Computers and Technology, 23.06.2019 17:30
Scientists have changed the model of the atom as they have gathered new evidence. one of the atomic models is shown below. what experimental evidence led to the development of this atomic model from the one before it? a few of the positive particles aimed at a gold foil seemed to bounce back. the colors of light emitted from heated atoms had very specific energies. experiments with water vapor showed that elements combine in specific proportions. cathode rays were bent in the same way whenever a magnet was brought near them.
Answers: 2
You know the right answer?
Objectives: number system, bitwise operations, masking. main() function: 1. declare an int variabl...
Questions
question
Mathematics, 09.04.2021 01:10
question
History, 09.04.2021 01:10
question
Mathematics, 09.04.2021 01:10
question
Mathematics, 09.04.2021 01:10
question
Mathematics, 09.04.2021 01:10
Questions on the website: 13722362