there are various ways to represent negative numbers in a binary system, why doesnt a computer get confused?
For example, with 3 bits, ones compliment
010 = 2
101 can mean 7 or -2
as far as I can tell, other methods have problems as well
the question is, how do you avoid problems like this? why does a computer know that you're using a negative and not a straight up binary number?
simple binary question (negatives)
Page 1 of 16 Replies - 1694 Views - Last Post: 24 January 2013 - 09:48 AM
Replies To: simple binary question (negatives)
#2
Re: simple binary question (negatives)
Posted 21 January 2013 - 07:05 PM
Certain data types are signed, and others are unsigned. Even at the assembly level, there are various jump statements that deal with signed values, and others that are similar but deal with unsigned values.
#3
Re: simple binary question (negatives)
Posted 21 January 2013 - 08:57 PM
macosxnerd101, on 21 January 2013 - 07:05 PM, said:
Certain data types are signed, and others are unsigned. Even at the assembly level, there are various jump statements that deal with signed values, and others that are similar but deal with unsigned values.
I dont think I understand you, a binary representation of a negative number doesnt use a sign, it uses its digits, and since it uses its digits, the string for a certain negative number can theoretically mean something else as well.
can you give more detail?
#4
Re: simple binary question (negatives)
Posted 21 January 2013 - 09:29 PM
There are signed and unsigned variables. C/C++ both make uses of these types of variables. A signed variable can have positive or negative values, while an unsigned variable can only have positive values. So if you have a signed variable with the high bit as a 1, then it will be seen as a negative number. If you have an unsigned variable with the high bit as a 1, it's still positive. Operators will take this into account.
When you really get down into Assembly, you can see this happening just with the JUMP instructions. See the Intel x86 reference for an example.
When you really get down into Assembly, you can see this happening just with the JUMP instructions. See the Intel x86 reference for an example.
#5
Re: simple binary question (negatives)
Posted 22 January 2013 - 09:11 PM
So is this making sense now? Is this question resolved?
#6
Re: simple binary question (negatives)
Posted 24 January 2013 - 08:25 AM
No one has pointed out that 101 would be 5 or -3, not 7 or -2. 7 is 111, and -2 is 110 (two's compliment).
I know, I'm petty like that.
I know, I'm petty like that.
#7
Re: simple binary question (negatives)
Posted 24 January 2013 - 09:48 AM
Not petty enough. He specified that he is using one's complement so 101 is 5 or -2.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote








|