Question: A protocol is a set of rules that define some operation. For example, the Internet Protocol (IP) specifies how messages are routed throughout the internet.

A protocol is a set of rules that define some operation. For example, the Internet Protocol (IP)

specifies how messages are routed throughout the internet. In this problem, you are asked to

implement your 1st messaging protocol (MP1). MP1 is a binary protocol that is used to efficiently

encode a set of arithmetic operations using a 4-byte data type (e.g., int). The specification of the

protocol is as follow. Using a 4-byte (32-bit stream), MP1 messages encode the +, -, *,

/ arithmetic operations in the first two most significant bits of the bit stream as seen below.

Bits 31, 30 Description
0 0 Addition operation
0 1 Subtraction operation
1 0 Multiplication operation
1 1 Division operation

The arithmetic operations carried by an MP1 message (defined in Table) are executed using

two operands, a left-hand-side (lhs) operand, and a right-hand-side (rhs) operand, as seen below:

lhs > rhs

MP1 messages encode two 15-bit values used to represent both lhs and rhs operands. The lhs

numeric value is encoded in bits 29 15, while the rhs numeric value is encoded in bits 14 0.

Thus, the complete encoding of the MP1 message is as seen below.

A protocol is a set of rules that define some operation. For

Design and implement a C++ program that uses the MP1 protocol to perform arithmetic computations on short data types. Your code shall include the following functions: // This function receives a lhs operand, rhs operand, and operator and packs it into // a 32-bit stream per the MP1 messaging protocol. The return value is the packed // 32-bit (uint) stream that can be unpacked/decoded to execute arithmetic operations. uint packMessage(ushort lhsNumber, ushort rhsNumber, char operation); // This function receives an MP1 message (uint), unpacks/decodes it, and process it to // return the result of the operation carried within the message. For valid operation // and data values, please refer to the MP1 protocol specification. double processMessage(uint message); In your implementation for both functions above, you shall use a switch statement. Every bit-mask used throughout the program shall be in the form of constant expression. Please note that each operand has a maximum value of 2^15, so your code must perform appropriate error checking before attempting to encode a number in the MP1 message. Your functions shall match exactly the declaration above. When your program executes, it must do so infinitely, always prompting users to enter the lhs operand, followed by the operation, followed by the rhs operands, as seen below.

example, the Internet Protocol (IP) specifies how messages are routed throughout the

On each operand (lhs and rhs) your code shall implement error checks for the conditions presented as shown on figure:

internet. In this problem, you are asked to implement your 1st messaging

Similarly, your code shall check for invalid input on the operation, ensuring that only the valid values defined in the MP1 protocol are accepted, as seen in Figure:

protocol (MP1). MP1 is a binary protocol that is used to efficiently

Inside your main function, your result shall be displayed to the console using the following code. // TODO: Add code here to request input (lhs/rhs/operation) from user and validate it. // ... // At this point, all inputs have been validated, so we can move forward with processing. cout /* Message Protocol (MP1): Val: lhs rhs Bit pos: Bit stream: Val Id: 31-30 29- 23 22 15 148 7- 0 The two most significant bits (zz) encode the arithmetic operations as seen below: 00'} addition, 01' subtraction, 10 multiplication, 11 "/} division The bits 29 15 (xxxxxxx xxxxxxxx) represent the lhs operand with maximum value of 2 15. The bits 14 0 (yyyyyyy yyyyyyyy) represent the rhs operand with maximum value of 2 15

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!