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, 23.06.2019 18:30
How often does colleges update the cost of attendance on their website? . a)every two years b) every four years c) every year d) every semester
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
Apart from confidential information, what other information does nda to outline? ndas not only outline confidential information, but they also enable you to outline .
Answers: 1
question
Computers and Technology, 24.06.2019 07:50
Write a defining table and then a program that determines if you can sleep in or not. your program should get all its input from your computer’s clock. on all weekdays (monday through friday) that are not holidays, your program should output “get up! ” on all other days (weekends and holidays), your program should output “sleep in.” the three holidays that your program must check for are january 1 (new year’s day), july 4 (u.s. independence day), and december 25 (christmas). you don’t need to include other holidays in your program because most other holidays do not occur on a fixed day each year.
Answers: 1
question
Computers and Technology, 25.06.2019 05:10
What is the disadvantage of a mesh topology?
Answers: 1
You know the right answer?
Objectives: number system, bitwise operations, masking. main() function: 1. declare an int variabl...
Questions
question
Mathematics, 15.04.2021 21:00
question
Mathematics, 15.04.2021 21:00
question
Mathematics, 15.04.2021 21:00
question
English, 15.04.2021 21:00
Questions on the website: 13722361