Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need guidance on what I am doing wrong. The wbitadd function is supposed to implement 2's compliment on m and n then add those

I need guidance on what I am doing wrong. The wbitadd function is supposed to implement 2's compliment on m and n then add those two integers together. Some results are correct, some are correct but wrong format and others are completely wrong.
image text in transcribed
image text in transcribed
image text in transcribed
long wbitadd(const unsigned char W, const unsigned long m, const unsigned long n, unsigned long result) { int signed long newm = (mm)+1;//change to signed int signed long newn - (n)+1; *result = newm + newn;/add m and n and store in veseid #include int wbitadd(const unsigned char W, const unsigned long m, const unsigned long n, unsigned long *result). int main() { unsigned char w = 28; unsigned long m = Oxffff000; unsigned long n = 0x12307fff000; unsigned long sum; int overflow; overflow = ! wbitadd(w,m,n,&sum); printf("%d-bit Ox%1% + 0x%1x = 0x%1x ",w, m, n, sum); -1x if (overflow) printf("(overflows)"); putchar(' '); return 0; You are to implement a simple function with the following type declaration: long wbitadd(const unsigned char w, const unsigned long m, const unsigned long n, unsigned long result); This function implements two's complement (signed) addition on the second and third arguments, which are interpreted as w-bit signed integers, where w is the first argument. The w-bit result is placed in the location pointed to by the fourth argument. The function returns 0 if the addition operation overflows, and 1 otherwise. In other words, the return value, interpreted as a boolean, indicates whether a valid result has been returned, so it can be used in the following way: if (wbitadd (width, addendi, addend2, &sum)) { // sum contains the valid result } else // handle overflow ) The preconditions for this function, which you may assume are satisfied, are as follows

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago