views:

167

answers:

5

I was reading some assembly tutorial in which there were explained the signed integers and the unsigned integers and the difference between their representation in computer memory.

I remember something like that there was some bit at the beginning at the number so it tells whether the integer is unsigned or signed.

If someone knows it, please answer.

+2  A: 

There are many possible representations of signed numbers, the most common is two's complement.

Alexander Gessler
But..That's not exactly what i wanted to read...How are they represented in the computer memory ? How does the machine (or compiler) knows that the int is signed or unsigned ? etc.
VaioIsBorn
The machine doesn't know - which is why you have to tell the compiler how to treat it. In memory, it's just represented as a specific number of bits, which can be anything...
Reed Copsey
It's related, because two's complement is tricky enough to allow many operations to work with unsigned and signed data equally, for example addition.
Alexander Gessler
+2  A: 

Wikipedia's page on Signed Number representation shows the most common memory implementations of both signed and unsigned integer values.

Two's compliment is the most common representation.

Reed Copsey
+1  A: 

The MSB does not determine whether or not the number is signed; in signed numbers it represents whether the number is negative. In unsigned numbers it's just the MSB. It's the program that determines whether a number is considered signed or unsigned.

Ignacio Vazquez-Abrams
+1  A: 

he he. tricky question. signed and unsigned integers are represented exactly same. looking at memory you will never be able to distinguish them. it comes out of one of Von Neumann's principle. So where is difference? Difference is in the way they are interpreted. If variable is signed compiler uses commands for signed ints. Also if we know that number is signed it's first bit tells us it's sign. the conversion is done as ~i + 1 (c syntax) in both ways

Andrey
A: 

There are many possible representations, each one depending on your computer's organization. The most famous are

On both representations, you can test the first (most significant) bit to find out whether the number is positive (usually off) or negative (bit on). That is, if you treat the number as signed. If you tell the compiler to treat such numbers as unsigned, the sign bit is used as data (which doubles the maximum range for the data type).

Bruno Brant