Binary - negative numbers
Article Index
Binary - negative numbers
Octal
Getting negative
The complement
Binary complements

Being negative about binary

Binary is the computer way. While we might carry on using our outmoded base ten methods with the most minor of excuses - why let the possession of ten fingers influence your choice of number base - computers do everything with zero and one. We have already looked the basics of why binary is so attractive from a computer's point of view.

Put simply you can represent a binary number using nothing but two electronic states - usually high and low voltage. You can also manipulate a binary number using Boolean logic and, while the connection between logic and arithmetic is far from obvious, it does all fit together remarkably well. Notice that there is no such cosy relationship between decimal notation and any sort of easy to implement logic.

Logic and arithmetic

Two-valued arithmetic and two-valued logic fit so well together that you almost don't notice that they are quite different things. You can be talking about Boolean logic one minute with truth tables, And, Or and Not gates, and the next you are dealing with half and full adders that appear to be all about logic but designed to do arithmetic.

The point is that Boolean logic simply realises the "addition tables" that characterise binary arithmetic. That is, to add two bits together all you need is a lookup table of results:

A  B  R  C
0 0 0 0
0 1 1 0
1 0 1 0
1 1 1 1

If you want to add bit A to bit B to produce a two-bit result R and C then all you have to do is look up the entry in the table and read off the answer. All arithmetic is done this way, no matter what base you are working in. Don't believe me? Well how do you add 3 to 6? You use a lookup table that was loaded into your, hopefully non-volatile, memory back when you were being instructed in such things. Without the lookup table you haven't a clue how to add two digits unless you actually "do" the addition, with marbles say, and count the final result.

Once you have the addition table for the digits in any base then you can do addition of any multi-digit numbers by following the place value algorithm - add the first two digits, write down the result and pass the carry onto the addition of the next two digits and so on. The only complication is that after the first two digits you have to involve the carry from the previous addition but this isn't too difficult.

The connection between binary arithmetic and Boolean logic is that its lookup table for addition can be treated as if it was a truth table and implemented using logic gates. What is interesting is that the lookup table for binary has only four lines but decimal has 100! You need to know what every digit added to every other digit gives as a result. We don't really store a 100-line table in our head's because we are "clever" enough to notice the regularities - 0 added to any digit doesn't make any difference, x+y is the same as y+x and so on. Still you do need to maintain 40 or so table entries to do decimal arithmetic and this is presumably why it is so hard to learn at first. If we switched to binary a four-line table would at least be easy to remember.

<ASIN:B001RCL5SQ@COM@CA>

<ASIN:0072129905>

<ASIN:0130620130>

 



 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2012 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.