# simple binary question (negatives)

Page 1 of 1

## 6 Replies - 2377 Views - Last Post: 24 January 2013 - 09:48 AM

### #1 NecroWinter

• D.I.C Regular

Reputation: 38
• Posts: 328
• Joined: 21-October 11

# simple binary question (negatives)

Posted 21 January 2013 - 07:02 PM

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?
Is This A Good Question/Topic? 0

## Replies To: simple binary question (negatives)

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11758
• Posts: 44,175
• Joined: 27-December 08

## 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.
Was This Post Helpful? 1

### #3 NecroWinter

• D.I.C Regular

Reputation: 38
• Posts: 328
• Joined: 21-October 11

## 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?
Was This Post Helpful? 0

### #4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11758
• Posts: 44,175
• Joined: 27-December 08

## 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.
Was This Post Helpful? 1

### #5 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11758
• Posts: 44,175
• Joined: 27-December 08

## Re: simple binary question (negatives)

Posted 22 January 2013 - 09:11 PM

So is this making sense now? Is this question resolved?
Was This Post Helpful? 0

### #6 lordofduct

• I'm a cheeseburger

Reputation: 2582
• Posts: 4,702
• Joined: 24-September 10

## 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.
Was This Post Helpful? 1

### #7 mojo666

• D.I.C Addict

Reputation: 397
• Posts: 856
• Joined: 27-June 09

## 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.
Was This Post Helpful? 3

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}