Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program: Write a C program to extract information from a whole number referred to as the code. The information is needed to carry out a

Program:

Write a C program to extract information from a whole number referred to as the code. The information is needed to carry out a secret mission. Hidden data embedded in the code are:

The password: The lowest 4 bits in the number represent the password.

The safety signal: The 8th bit from the right is a signal. 1 indicates safety and 0 indicates danger.

Number of missiles: The value of bits 4, 5, 6 from the right represents the number of missiles.

Function Prototype:

Write function prototypes at the beginning of the program before main().

Write the function definitions (the code) after main().

Required Function: Every function must be preceded with 4 lines of comments describing its name, input(s), output type, and task.

1) get_code() function

-Input parameter: None

- Output: int

-Task: prompt the user to enter a whole number in range of -4000 and 4000, both ````inclusive (values in this range fir in 2 bytes (16 bits) in memory

```` Validation: Use a loop to validate the range of the number.

2) display_binary() function

- Input parameter: int

- Output: void

-Task: Display the input number in 16 bit binary.

Display a space between every 4 bits for clarity.

main( )

Declare variables of type int to store the code, password, signal, missiles,

Invoke the function get_code() and store its output in variable code.

Display the code in hexadecimal (use %X in printf ).

Invoke the function display_binary ( ) to display the code in binary.

Declare a mask for password - the lowest 4 bits in the code.

Use this mask to retrieve the password and store it in a variable.

Display the password to the screen.

Declare a mask to retrieve the signal.

Use the mask to retrieve the signal - Display the outcome to the screen.

Declare a mask to retrieve the number of missiles in this mission.

Use the mask to retrieve the number of missiles. Display it to the screen.

Ouput:

image text in transcribed

CAFall 2017105 Assignments Lab Solutions Debug\Lab Solutions.exe x CNIT105 Assignment 10 Output A Secret Mission Enter a whole number between 20 and 2000: 165 The code is: 165 The code in Hexadecimal: A5 The code in binary: 0000 0000 1010 0101 The password is: 5 The signal is: 1 Safe to Proceed Number of missiles in this mission is: 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions