views:

673

answers:

8

History: I read from one of Knuth's algorithm book that first computers used the base of 10. Then, it switched to two's complement here.

Question: Why does the base could not be -2 in at least a monoid?

Examples:

(-2)^1 = -2 
(-2)^3 = -8
A: 

1's compliment does have 0 and -0 - is that what you're after?

CDC used to produce 1's compliment machines which made negation very easy as you suggest. As I understand it, it also allowed them to produce hardware for subtraction that didn't infringe on IBM's patent on the 2's compliment binary subtractor.

n8wrl
+16  A: 

At its heart, digital logic is base two. A digital signal is either on or off. Supporting other bases (as in BCD) means wasted representation space, more engineering, more complex specification, etc.

Editted to add: In addition to the trivial representation of a single binary digit in digital logic, addition is easily realized in hardware, start half adder which is easily realized in Boolean logic (i.e. with transistors):

   (No carry) (with carry)
  |  0   1      0   1
--+--------------------
0 | 00  01     01  10
1 | 01  10     10  11

(the returned digit is (A xor B) xor C, and the carry is ((A and B) or (C and (A or B))) ) which are then chained together to generate a full register adder.

Which brings us to twos complement: negation is easy, and the addition of mixed positive and negative number follows naturally with no additional hardware. So subtraction comes almost for free.

Few other representations will allow arithmetic to be implemented so cheaply, and I know of none that are easier.

dmckee
dmackee: Good point. I was thinking it. It is much more complex to handle the base of -2, but it has some nice properties. For example, you can multiply any number like: 2_10 * 1000_(-2) (where 10 and -2 are bases), then you get 10000_(-2) + 2* 1000_(-2) = 0. It actually very cool thing, it is like having a switch to turn a machine off just by multiplying by 2.
Masi
You just answered your own question: "It is much more complex to handle the base of -2". CPU designers do not want complexity. They want efficiency.
jalf
I feel that the method does not really make things more complex, it only moves the complexity. The reason for the question lies partly in the idea about Crash-only Machines. If the states were trasferred to a upper level by a new design of the whole base, I feel it would be much more simpler to design processes you can simply turn off and on. Not 100% sure though. I hope you can see where I am aiming at!
Masi
+3  A: 

Optimization in storage and optimization in processing time are often at cross purposes with each other; all other things being equal, simplicity usually trumps complexity.

Anyone can propose any storage mechanism for information they wish, but unless there are processors or algorithms that support it, it won't get used.

Jason S
A: 

In the end the decision was made because of voltage variance.

With base 2 it is on or off, no in between.

However with base 10 how do you know what each number is?

is .1 volts 1? What about .11? Voltage can vary and is not precise. Which is why an analog signal is not as good as a digital. This is if you pay more for a HDMI cable than $6 it is a waste, it is digital it gets there or not. Audio it does matter because the signal can change.

David Basarab
Not really true about digital cabling - the better better the cable is at rejecting (analogue) noise, the less likely it will "flip" a bit from 1->0 or 0->1.
Draemon
Digital and analogue signals are affected differently by noise of course - generally speaking a digital signal is more tolerant of noise, but tends to have a more dramatic effect when the noise becomes an issue. Compare old analogue TV which degrades easily but gradually vs digital which is more resilient but when it fails it really fails.
Draemon
+1 for physical perspective.
Masi
I agree -- it's easier to calculate on or off than 10 different voltage levels. Analog computers took this a step farther, essentially using a voltage level for floating point values. It was a little more complex than that, of course, but the precision wasn't quite as good as digital computers.
xpda
+17  A: 

The problem is that with a negabinary (base -2) system, it's more difficult to understand, and the number of possible positive and negative values are different. To see this latter point, consider a simple 3 bit case.

Here the first (rightmost) bit represents the decimal 1; the middle bit represents the decimal -2; and the third (leftmost) bit represents the decimal 4

So

000 -> 0

001 -> 1

010 -> -2

011 -> -1

100 -> 4

101 -> 5

110 -> 2

111 -> 3

Thus the range of expressable values is -2 to 5, i.e. non-symmetric.

Richie Cotton
+1 The first one to answer the question.
balpha
such an asymmetric range would be a pain to work with... +1
jalf
@balpha: It answers "why not base -2" but not "why base 2" which as others have pointed out has to do with electrical characteristics.
Draemon
You should look at the gray code. It doesn't go exactly like this, but close -- there is a pattern everywhere.
nik
@Draemon: You only need two digits when working with base (-2) -- just as you do when working with base 2. So electrical characteristics don't prevent you from using base (-2) -- it's still just ON or OFF.
balpha
The range of expressable values in "regular" binary is non-symmetric (-4 to +3, -32768 to +32767, etc)
Jason S
A: 

Please, see an example of the complexity that dmckee pointed out without examples. So you can see an example, the numbers 0-9:

0 = 0
1 = 1
2 = 110
3 = 111
4 = 100
5 = 101
6 = 11010
7 = 11011
8 = 11000
9 = 11001
Masi
+2  A: 

Also, the use of the binary system has a mathematical background. Consider the Information Theory by Claude Shannon . My english skills don't qualify to explain this topic, so better follow the link to wikipedia and enjoy the maths behind all this stuff.

Rodrigo
+1 Great thanks for mentioning the place for further study!
Masi
+3  A: 

There are two reasons to choose base 2 over base -2:

First, in a lot of applications you don't need to represent negative numbers. By isolating their representation to a single bit you can either expand the range of representable numbers, or reduce the storage space required when negative numbers aren't needed. In base -2 you need to include the negative values even if you clip the range.

Second, 2s complement hardware is simple to implement. Not only is simple to implement, it is super simple to implement 2s complement hardware that supports both signed and unsigned arithmetic, since they are the same thing. In other words, the binary representation of uint4(8) and sint4(-15) are the same, and the binary representation of uint(7) and sint4(7) are the same, which means you can do the addition without knowing whether or not it is signed, the values all work out either way. That means the HW can totally avoid knowing anything about signs and let it be dealt with as a language convention.

Louis Gerbarg