Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please in simple C++ Adding 4-bit numbers Write a function with the following prototype: string add(string a, string b, int & flags); On entry: Awc

Please in simple 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.

Annotations

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

More Books

Students also viewed these Databases questions

Question

3. Outline the four major approaches to informative speeches

Answered: 1 week ago

Question

4. Employ strategies to make your audience hungry for information

Answered: 1 week ago