GIDForums

Go Back   GIDForums > Computer Programming Forums > Miscellaneous Programming Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Sep-2007, 00:06
fishguts fishguts is offline
New Member
 
Join Date: Sep 2007
Posts: 3
fishguts is on a distinguished road

New to programming (Homework Help)


Good evening. I am a computer science major and new to all the programming and such. I am having problems with some of my homework.

I have to add these numbers using twos complement.

1010+1101=
0100+1011=
1010+0100=
1101+1011=

I dunno if i am doing this right but I get


1010+1101=0101+0010=0101
0100+1011=1011+0100=1111
1010+0100=0101+1011=1 1000
1101+1011=0010+0100=0110

Are these correct? How would I go adding these numbers using twos complement. I also habe another homework problem that is kinda stressing me out and I do not know how to go solving it.

Assuming common Intel (i386) float representation, 32 bits (sign 1 bit, exponent 8 bits, mantissa 2 bits)

What is the largest positive number you can represent?
what is the smallest non-zero number you can represent?
what is the smallest negative non zero number you can represent?



Any help would be GREATLY appreciated.
  #2  
Old 12-Sep-2007, 10:50
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,520
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: New to programming (Homework Help)


Quote:
Originally Posted by fishguts
...I have to add these numbers using twos complement...if i am doing this right

Are you assuming four-bit binary numbers that represent 2's complement signed integers?

Then the values are:
Code:
1000 binary = -8 decimal 1001 binary = -7 decimal 1010 binary = -6 decimal 1011 binary = -5 decimal 1100 binary = -4 decimal 1101 binary = -3 decimal 1110 binary = -2 decimal 1111 binary = -1 decimal 0000 binary = 0 decimal 0001 binary = 1 decimal . . . 0111 binary = 7 decimal
The big advantage of 2's complement representation of signed integers is that addition follows the rules of 'straight' binary addition. If there was no overflow, you will the the "right" answer.

If I just add the first two using binary arithmetic:
Code:
1010 binary + 1101 binary = 1 0111 binary
If I'm only supposed to use 4-bit arithmetic then the result is 0111 binary.

If I convert the numbers to decimal and add them I get
Code:
1010 binary + 1101 binary = (-6) decimal + (-3) decimal = (-9) decimal

Note that -9 decimal is not representable in our 4-bit 2's complement number system. What happened? It's called overflow. Looking back at the binary results, we see that we added two negative numbers and got a positive number. (That's probably bad, right?)

Note that if I add a negative number and a positive number, there can't possibly be an overflow, right?

But adding two positive numbers may (or may not) result in an overflow, as is in the case of adding two negative numbers.

Quote:
Originally Posted by fishguts
How would I go adding these numbers using twos complement.

Don't you have a book? Aren't there any explanations/examples?

Just do "straight" binary addition: Start with least significant bits. Add the bits according to the definition of binary addition and then move up the line. At each bit you add in the carry from the next less significant bit addition.

Quote:
Originally Posted by fishguts
Assuming common Intel (i386) float representation, 32 bits (sign 1 bit, exponent 8 bits, mantissa 2 bits)
Huh? Why don't they add up to 32 bits? Intel didn't invent floating point, you know. Maybe the assignment is referring to IEEE 754

Quote:
Originally Posted by fishguts
What is the largest positive number you can represent?
It is the (positive) number with the largest possible exponent value and the largest possible mantissa value, right? Then, according to the rules that you must have been given for evaluating floating point numbers, what is the decimal value?
Quote:
Originally Posted by fishguts
what is the smallest negative non zero number you can represent?
Do you mean the negative number closest to zero (the negative number with smallest absolute value), or the most negative number that can be represented?


Regards,

Dave
Last edited by davekw7x : 12-Sep-2007 at 11:36.
 

Recent GIDBlogUpdates On The All New Toyota VIOS - Part III by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few questions for someone in the programming industry. WAEvans Miscellaneous Programming Forum 0 08-Oct-2006 09:19
Looking for opinions crystalattice Miscellaneous Programming Forum 6 27-Sep-2006 21:02
printer / font color / windows programming nicolas_qc MS Visual C++ / MFC Forum 0 03-Jan-2006 23:13
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
GUI programming crystalattice CPP / C++ Forum 5 14-Sep-2004 12:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:57.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.