Computing.Net > Forums > Programming > Addition Hexa

Addition Hexa

Reply to Message Icon

Original Message
Name: manojkumar.paul
Date: July 18, 2007 at 23:45:31 Pacific
Subject: Addition Hexa
OS: Windows 2000
CPU/Ram: 512
Model/Manufacturer: Intel
Comment:

Hello friends.

Please help me out. Tomorrow is my class test. I need to pass it any how. But I have a problem solving one of the program.

Can you tell me the result of adding the 16-bit 2’s complement numbers (represented in Hex): 7847 + FF52 ?

Please help me out.
Thank you in advance.

Manoj Kumar Paul
Software Developer
Java


Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: July 18, 2007 at 23:50:40 Pacific
Reply: (edit)

You want us to add the two numbers, take the two's complement of both of those numbers and add them, or are you saying one is the two's complement of the other? Because if it's the later, the numbers are wrong.


Report Offensive Follow Up For Removal

Response Number 2
Name: manojkumar.paul
Date: July 18, 2007 at 23:53:35 Pacific
Reply: (edit)

I did it in the following way..

**************************************
(Hexa)

7847
FF52
-
17799
-

(Decimal equivalent)

30791
65362
-
96153
-

(Binary equivalent)

0111 1000 0100 0111 (16 bits)
1111 1111 0101 0010 (16 bits)
-----
10111 0111 1001 1001 (17 bits)
-----
**************************************

Where am I wrong?
Can you please tell me?
I need your prestigious suggestion.
Thank you.

Manoj Kumar Paul
Software Developer
Java


Report Offensive Follow Up For Removal

Response Number 3
Name: manojkumar.paul
Date: July 18, 2007 at 23:56:12 Pacific
Reply: (edit)

reply to...

take the two's complement of both of those numbers and add them,

Yes Sir!.

But for that I need to convert both the Hexa number into binary, right sir?

Manoj Kumar Paul
Software Developer
Java


Report Offensive Follow Up For Removal

Response Number 4
Name: manojkumar.paul
Date: July 19, 2007 at 00:00:05 Pacific
Reply: (edit)

Respected Sir!

Please read this question.
************************************
Add the following 16-bit 2’s complement numbers (represented in Hex): 7847 + FF52 and indicate whether or not there is a carry and/or an overflow generated. Also, if no overflow, give the result in base-10 format.
************************************

That means sir, the hexa numbers are already 2's complement. Do I still need to compute the 2's complement of the Hexa number after converting them into binary?.

Please reply.
Thank you

Manoj Kumar Paul
Software Developer
Java


Report Offensive Follow Up For Removal

Response Number 5
Name: Razor2.3
Date: July 19, 2007 at 01:01:48 Pacific
Reply: (edit)

Sorry for the delay, work came up.

You don't HAVE to convert to base 2, it's just much, much easier.

7847(b16) + FF52(b16) = 7799(b16) = 30617(b10), so your results are fine. You just have to remove the most significant bit, because it overflowed and doesn't count.

So yes, there is an overflow. If this were a base-32 system, your result would be accurate. As far as I can tell, as long as you remember that 1 digit of Hex = 4 digits of binary, you should be fine.


Report Offensive Follow Up For Removal


Response Number 6
Name: manojkumar.paul
Date: July 19, 2007 at 01:05:56 Pacific
Reply: (edit)

Thank you Razor2.3,
Thanks a lot.

You have cleared my doubts.

How can I removed the most significant bit, and what will be my final answer of the addition?
Please advice.

Thanks once again.

Manoj Kumar Paul
Software Developer
Java


Report Offensive Follow Up For Removal

Response Number 7
Name: Razor2.3
Date: July 19, 2007 at 01:08:21 Pacific
Reply: (edit)

If he wanted you to take the 2's complement of the second number, and then add them, the result would be:
(7847 + 00AE = 78F5)b16
(30791 - (-174) = 30965)b10

I could see him asking for that, as that's how computers do subtraction.

EDIT: How do you get rid of the overflow? It's up to you. You can just not include it in the conversion.

What answer you give is up to you, but depending on if you did a 2's complement (no overflow, see this post) or not (overflow, two possible values depending on if he want the "real" answer [yours] or what a computer would get [yours – overflow]).


Report Offensive Follow Up For Removal

Response Number 8
Name: Razor2.3
Date: July 19, 2007 at 01:19:20 Pacific
Reply: (edit)

To avoid any language confusion: the most significant bit would be the one on the left, and that's the one that's dropped by the CPU.


Report Offensive Follow Up For Removal

Response Number 9
Name: manojkumar.paul
Date: July 19, 2007 at 01:37:10 Pacific
Reply: (edit)

Thank you Razor2.3,
Thanks for the answer.

This is one question which has cleared many doubts in my mind. Although I was confident of my answer but just needed some suggestion, and its great to clear from someone of your caliber. Thank you Sir.

Manoj Kumar Paul
Software Developer
Java


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Addition Hexa

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge