One binary number can represent both a positive and negative integer right?
For example 1001 can be 9 or 7.
If this is true, how does the computer differentiate a positive and negative number?
I know if we wrote it out into into 8 bit,
9 = 0000 1001
and
 7 = 1111 1001
But what if I had 1111 1111. It would be 255 or 1. But there aren't any more preceding bits to determine if it's a negative or positive.
Maybe I'm misunderstanding something. Can someone clear this up? Thanks.
Binary representation in Integers
Page 1 of 16 Replies  997 Views  Last Post: 28 October 2013  05:30 AM
Replies To: Binary representation in Integers
#2
Re: Binary representation in Integers
Posted 26 October 2013  05:15 PM
The left most bit is used to tell the sign of the integer. As for how the computer tells the difference, check out One's Complement and Two's complement to learn more about how computers store presentation of signs for integer numbers.
This post has been edited by Martyr2: 26 October 2013  05:17 PM
#3
Re: Binary representation in Integers
Posted 26 October 2013  05:27 PM
Ohhhhh I see now...In an 8 bit system you wouldn't have 255 to 255.
You would only be able to get 128 to 127...128 being 10000000 and 127 being 01111111.
Thanks!
You would only be able to get 128 to 127...128 being 10000000 and 127 being 01111111.
Thanks!
#4
Re: Binary representation in Integers
Posted 27 October 2013  07:56 AM
The determination of whether or not a number is signed or unsigned is based upon which flags are checked / not checked.
#5
Re: Binary representation in Integers
Posted 27 October 2013  11:17 AM
#6
Re: Binary representation in Integers
Posted 27 October 2013  06:34 PM
Quote
The determination of whether or not a number is signed or unsigned is based upon which flags are checked / not checked.
This is not always true. In general, a number is signed if the MSB is set.
Not all instructions set the Sign Flag, so how would you know if the number is signed or not? You would check the Most Significant Bit.
mov eax, 1
Will not set the Sign flag in the EFLAGS register.
mov eax, 1 sub eax, 2
This WILL set the sign flag in the EFLAGS register.
The CPU only sets the sign flag with certain instructions.
http://en.wikipedia..../FLAGS_register
The only time the Sign Flag is set:
 All arithmetic operations except multiplication and division;
 compare instructions (equivalent to subtract instructions without storing the result);
 Logical instructions  XOR, AND, OR;
 TEST instructions (equivalent to AND instructions without storing the result).
#7
Re: Binary representation in Integers
Posted 28 October 2013  05:30 AM
The processor doesn't care for the most part is the most significant bit is set or not, but will turn on the sign flag(SF) if it is, or if it comes on. If you are working with an abstraction that says that a number is signed then monitoring the SF is important. If the abstraction is unsigned the SF doesn't matter.
SF turns on in both cases
signed byte = 0111 1111 + 1 = 1000 0000 is not legal
unsigned = 0111 1111 + 1 = 1000 0000 is legal
The other flag that is monitored is the carry flag(CF).
SF turns on in both cases
signed byte = 0111 1111 + 1 = 1000 0000 is not legal
unsigned = 0111 1111 + 1 = 1000 0000 is legal
The other flag that is monitored is the carry flag(CF).
This post has been edited by dbasnett: 28 October 2013  05:32 AM
Page 1 of 1
