PDA

Click to See Complete Forum and Search --> : [RESOLVED] What system does a computer use...


Nightwalker83
Feb 15th, 2010, 07:44 PM
Hi,

I'm not sure if this is the correct forum to post this in but the question is part of a maths assignment. The question is: What system does a computer use in order to distinguish between positive and negative numbers when it stores them in memory? (How is the number of bits changed from those used to express the namber usually?)

I don't understand to what the question is referring to, I am thinking the system is binary I can't remember reading about how it distinguishes between positive and negative numbers.

Thanks


Nightwalker

jemidiah
Feb 15th, 2010, 09:28 PM
It's almost certainly referring to two's complement. If the question is as written, though, it's ambiguous because there are a lot of different schemes to encode both positive and negative numbers in binary for use by computers. The advantage of two's complement is that it uses the same hardware for adding and subtracting, and it has reasonable overflow values. Oh, it also doesn't have +0 and -0 as separate binary strings, which the other encoding system I'm aware of (stick a 1 out front for negative, a 0 for positive) has.

Nightwalker83
Feb 15th, 2010, 10:06 PM
Yeah, the question is a bit ambiguous! I tried looking in the chapters of the textbook we were give for the answer but I couldn't find anything mentioning negative binary numbers as suggested above. I will see if my class mates had any luck understanding the problem and ask them how they found the solution failing that I will have to tracking down my lecturer and ask him about the question.

jemidiah
Feb 16th, 2010, 12:53 AM
I wouldn't ignore two's complement (http://en.wikipedia.org/wiki/Two%27s_complement). From the article, "this system is the most common method of representing signed integers on computers." The answer to the question above, if it's going from unsigned integer representations to signed integer representations using two's complement is that the number of bits increases by 1. That is, to express 255, you use 1111 1111 (unsigned) or 0 1111 1111 (two's complement signed), meaning you had to add a bit.

Nightwalker83
Feb 16th, 2010, 02:54 AM
Thanks for the help! I asked a class mate what he thought the problem was asking and this was his solution:


A sign bit

Example in a 32 bit integer only 31 bits are used to store the value. The other one is used to store the negative/positive value.

wossname
Feb 19th, 2010, 02:43 PM
In a nutshell, the high bit of any register (when regarded as a signed integral value) indicates the sign. But it's not that simple...

Using Intel's IA-32 architecture (basically Pentium family and a few notable others) if you expand a negative signed 16-bit value into a signed 32-but value, all of the high word's bits will be set high...

16-bit negative value (decimal -100)
1111111110011100
becomes...
11111111111111111111111110011100

This is a widening conversion so the CPU has to preserve the top bit by repeating it until the new 32-bit value is properly filled.

Of course the CPU has no particular interest in whether a value is signed or unsigned, it all depends on what operators you use to manipulate the data!

Assembly language is extremely rewarding if you can spend the time to learn a little more about it. I highly recommend it.