Wednesday, 15 February 2017

Binary Revision 2

Binary

Binary numbers are similar to decimal numbers. In the same way as each decimal digit is worth 10 times more than the digit to the right of it, each binary digit is worth 2 times more than the digit to the right of it. Also, in the same way as there are 10 possibilities in decimal (0-9), there are 2 possibilities in binary (0 or 1). This is why decimal is known as "base-10", and binary is known as "base-2".
For example, the number "10" would be written as "1010" - 1 eight and 1 two.
8421 
1010(10)
The reason computers use binary (and not decimal, octal, or anything else) as their primary number system is because binary is digital - either electricity is flowing (binary 1), or electricity isn't flowing (binary 0).


Binary Negative

Two's Complement

11001001 can be interpreted as either 201 (using normal binary) or -55 (using two's complement). A question will tell you if it should be read using two's complement.
  1. Firstly, write the number in binary. For example, 54 becomes 00110110 in 8-bit binary.
  2. Then, invert the digits (i.e. 1s become 0s, and 0s become 1s), so 00110110 becomes 11001001.
  3. Finally, add 1 - 11001001 + 00000001 = 11001010.
-1286432168421 
11001010(-54)

Sign and Magnitude

Sign and magnitude uses the first bit for the sign (positive - 0, or negative - 1), and the remaining 7 bits for the number. For example, 11001011 represents -75. The first "1" means it is negative, and the remaining 7 bits (1001011) represent 75.
+/-6432168421 
11001011(-75)

Binary Addition

Binary addition is far easier than decimal addition! This is because there are only 4 possible sums - 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 0, carry 1 (or 10, decimal 2). For example:
 1286432168421 
 00101010(42)
+01100110(102)
Carry:11 111   
 10010000(144)
In an exam you must show your working to show that you didn't just convert the numbers to decimal, and then convert the solution from decimal back to binary.


Binary Subtraction

Binary subtraction can be done in two ways - just like decimal subtraction. You can either do 5 - 3, or -3 + 5 (using twos compliment - not sign and magnitude). Unless a question tells you to use twos compliment, you can use whichever method you prefer.

Using twos compliment:

 -1286432168421 
 11001000(-56)
+01100101(101)
Carry:11       
 00101101(45)

Using subtraction:

 1286432168421 
 10010100(148)
-00100111(39)
Carry:01101011 
 01101101(109)

No comments:

Post a Comment