User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Binary Page [1]  
volex
All American
1758 Posts
user info
edit post

So I had a test, got a prob wrong, was wondering if anyone could explain to me why I got it wrong so I can change my mindset for the final. Changed the question so it isn't the same but still the same type:

Find the following difference using twos complement arithmetic:

11001101
- 10001



[Edited on December 9, 2006 at 11:07 PM. Reason : k]

12/9/2006 11:06:45 PM

BigMan157
no u
103354 Posts
user info
edit post

-36?

man i've forgotten so much

[Edited on December 9, 2006 at 11:31 PM. Reason : unless it's 8-bit two's complement in which case that second number is positive]

[Edited on December 9, 2006 at 11:33 PM. Reason : and the ans would be -68]

12/9/2006 11:30:27 PM

Jere
Suspended
4838 Posts
user info
edit post

I got -68

12/9/2006 11:38:32 PM

volex
All American
1758 Posts
user info
edit post

dont you sign extend the second number before complementing?, as opposed to just padding

12/10/2006 12:10:20 AM

Jere
Suspended
4838 Posts
user info
edit post

I guess it depends on if you treat it as positive or negative. I would assume you treat as positive. It would be really ambiguous otherwise.

12/10/2006 12:11:46 AM

volex
All American
1758 Posts
user info
edit post

i always learned it as the left most bit is always the sign bit regardless of length, how else would you subtract two registers of different lengths?

12/10/2006 12:13:54 AM

Jere
Suspended
4838 Posts
user info
edit post

If that's the way you learned it, then I guess that's what is implied. I never really ran into that problem.

12/10/2006 12:17:08 AM

volex
All American
1758 Posts
user info
edit post

This is what I presented to prof. Say you have an 8 bit register and a 16 bit register.
Load the 8 bit register with -2 (11111110) and load the 16 bit register with -2 (1111...1110). Those two registers clearly twos complement to 2, which means they represent -2. Now subtract the 16 bit from the 8 bit. His way you get
1111...11111110 (-2)
0000...11111110 which is clearly not the same number

My way you get
1111...11111110 (-2)
1111...11111110 (-2)

I guess I just dont understand how you can pad 0's like they are insignificant on signed numbers like you can on unsigned

[Edited on December 10, 2006 at 12:24 AM. Reason : k]

12/10/2006 12:23:31 AM

EEstudent
All American
2595 Posts
user info
edit post

11001101 <-- this number is -00110011 in binary, -51 decimal
- 10001 <-- assuming this number is actually 00010001, 17 decimal
-----------

therefore...

-51
- 17
--------
-68 <-- the answer in decimal

12/10/2006 12:32:26 AM

EEstudent
All American
2595 Posts
user info
edit post

it all depends if you are assuming that the bits are in an 8 bit register or if they should be sign extended...it would be more cut and dry if the problem just said to subtract 11110001 instead of 10001 because usually you only operate on numbers of the same length. Like in the example above I assumed that the number 10001 was 00010001, but I'm not sure if it is more right to assume to sign extend it to 11110001. Maybe there is some convention for that, I don't know.


for more on this see --> http://en.wikipedia.org/wiki/Two's_complement#Subtraction


[Edited on December 10, 2006 at 12:41 AM. Reason : better explanation]

[Edited on December 10, 2006 at 12:44 AM. Reason : .]

12/10/2006 12:35:15 AM

volex
All American
1758 Posts
user info
edit post

I thought you always sign extended signed binary. For instance, unsigned
1 is the same as 01 is the same as 00000000001

but signed
1 is the same as 11 is the same as 1111111111

signed
1 is not the same as 01 or 000000001

12/10/2006 12:44:17 AM

moron
All American
34143 Posts
user info
edit post

Yeah, you would have to sign extend that, if you're using 2's complement.

So -51 - -15= -36

12/10/2006 2:24:46 AM

EEstudent
All American
2595 Posts
user info
edit post

^i concur...that makes the most sense to sign extend it unless the problem specifically states otherwise.

12/12/2006 2:02:32 AM

volex
All American
1758 Posts
user info
edit post

ah well, done arguing with prof, not surprised that he was wrong, as its on par with almost the entire course

12/12/2006 11:01:42 AM

EEstudent
All American
2595 Posts
user info
edit post

who is teaching your class?

12/12/2006 11:24:04 AM

BigMan157
no u
103354 Posts
user info
edit post

it was a poorly done question

which, yeah, is about par for the course for the EE program

12/12/2006 12:01:54 PM

WolfAce
All American
6458 Posts
user info
edit post

Yeah, who is the prof? So I can try to avoid them...

12/12/2006 12:17:37 PM

moron
All American
34143 Posts
user info
edit post

If the problem was done in the context of hardware design, then whether or not your compute it by sign extending would be unclear.

But if it was just a conceptual problem, then it would make more sense to sign extend it.

12/12/2006 2:40:40 PM

volex
All American
1758 Posts
user info
edit post

^ I'm not sure how you could ever lengthen any signed number without sign extending it, in any context.. unless you say, built a machine that did not store leading zeros on signed numbers, and that would just be silly


as for the prof - steve hunter, but this was for CSC, but he could probably teach on EE stuff as it was more an EE type class than CSC


actually upon further inspection he is primarily an EE teacher I believe, worst prof I've had at state though, cant wait for the eval at least!

[Edited on December 12, 2006 at 2:56 PM. Reason : gg]

12/12/2006 2:49:28 PM

BigDave41
All American
1301 Posts
user info
edit post

yeah...i had him for 2 weeks for ECE407 before i dropped it because it was at 8:05. if i remember correctly he worked at IBM and was an adjunct prof and just taught one class a semester.

seemed like a nice guy...but the few classes i attended weren't interesting enough to keep me coming to an 805 class

12/12/2006 5:59:44 PM

moron
All American
34143 Posts
user info
edit post

Quote :
"^ I'm not sure how you could ever lengthen any signed number without sign extending it, in any context.. unless you say, built a machine that did not store leading zeros on signed numbers, and that would just be silly"


Yeah, exactly. You would have to specially design the hardware for sign extension.

But if you given a basic adder, and you just plugged those in as they were, it would probably just zero fill.

12/12/2006 6:38:01 PM

volex
All American
1758 Posts
user info
edit post

oh well I guess thats how they do things over there at IBM they dont let anyone know they are wrong, just keep arguing for the incorrect solution

[Edited on December 12, 2006 at 10:03 PM. Reason : k]

12/12/2006 10:02:21 PM

 Message Boards » Tech Talk » Binary Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.