Question: Can someone help me with this C++ Adding 4-bit numbers Write a function with the following prototype: string add(string a, string b, int & flags);

Can someone help me with this C++

Adding 4-bit numbers

Write a function with the following prototype:

string add(string a, string b, int & flags);

On entry:

Awc (Assume without checking) each string param has size exactly 4, and each of the 4 chars in

both strings is either '0' or '1' (e.g. "0110", "1010").

Awc flags is UG (unpredictable garbage) on entry. One of add's jobs is to set this reference arg.

add may not assume that flags has been initialized to something sensible on entry.

add does no i/o (input/ouptut).

add's job is to return the string corresponding to the 4-bit sum of a and b, and to set flags so that

the high-order 28 bits are 0 and the the low-order 4 bits are the values for N, Z, V, and C,

respectively:

bit #28: N

bit #29: Z

bit #30: V

bit #31: C

For example, if a were "0110" and b were "1010":

0110

+ 1010

0000

N: 0, because the answer we got wasn't negative

Z: 1, because the answer we got was 0

V: 0, because with signed (2s complement) interpretation, 6 + -6 == 0 isnt wrong, and

C: 1, because with unsigned interpretation, 6 + 10 == 0 is wrong

So, the returned string is "0000" (the most significant bit being represented by the first char in the

string), and flags is set to 5, because 5 in binary is

NZVC

00000000 00000000 00000000 00000101

Write a main function that calls your add function. You decide the details of your main.

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!