![]() |
|
#1
|
|||
|
|||
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
|
|||||
|
|||||
Re: New to programming (Homework Help)Quote:
Are you assuming four-bit binary numbers that represent 2's complement signed integers? Then the values are: Code:
If I just add the first two using binary arithmetic: Code:
If I convert the numbers to decimal and add them I get Code:
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:
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:
Quote:
Quote:
Regards, Dave Last edited by davekw7x : 12-Sep-2007 at 11:36.
|
Recent GIDBlog
Updates On The All New Toyota VIOS - Part III by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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