Questions about this topic? Sign up to ask in the talk tab.

Difference between revisions of "Bitwise math/Introduction"

From NetSec
Jump to: navigation, search
 
Line 77: Line 77:
  
 
Through the use of the binary table, the binary values can each be multiplied (1’s) by the above multipliers (1x2^3 1x2^2 1x2^1 1x2^0) or “8, 4, 2, 1”. This will then give us, 8+4+2+1=15.
 
Through the use of the binary table, the binary values can each be multiplied (1’s) by the above multipliers (1x2^3 1x2^2 1x2^1 1x2^0) or “8, 4, 2, 1”. This will then give us, 8+4+2+1=15.
 +
 +
 +
=== Basic Addition ===
 +
 +
{{:Bitwise math/Introduction/Addition}}

Latest revision as of 06:37, 19 July 2012

back to Bitwise math


Binary math and hexadecimal math have slight differences to decimal math but the same principles apply. For example, in the decimal number 1234, the ‘4’ is in the “ones” placeholder, the ‘3’ is in the “tens” placeholder, the ‘2’ in the “hundreds” placeholder and the ‘1’ in the “thousands” placeholder.

Example 1: Decimal number 1234

Example 1: Decimal number 1234
Thousands (1x10^3) Hundreds (1x10^2) Tens (1x10^1) Ones (1x10^0)
1 2 3 4

Binary operates a little bit differently, instead of having 1’s, 10’s, 100’s, etc, it has 1’s, 2’s, 4’s, 8’s, etc (That is to say, decimal math operates on a base of 10, while binary math operates on a base of 2). So analysing this for a moment, the binary number 1010, has a ‘1’ in the “eights” placeholder and a ‘1’ in the “twos” placeholder. Add these together and 10 is obtained in decimal numbers.

Example 2: Binary number 1010 = 8+2 = Decimal number 10
Eights (1x2^3) Fours (1x2^2) Twos (1x2^1) Ones (1x2^0)
1 0 1 0

Another example is 1111:

Example 3: Binary number 1111 = 8+4+2+1 = Decimal number 15
Eights (1x2^3) Fours (1x2^2) Twos (1x2^1) Ones (1x2^0)
1 1 1 1


Detailed Example
Eights (1x2^3) Fours (1x2^2) Twos (1x2^1) Ones (1x2^0)
Binary Values 1 1 1 1
Decimal Values 8 4 2 1

Through the use of the binary table, the binary values can each be multiplied (1’s) by the above multipliers (1x2^3 1x2^2 1x2^1 1x2^0) or “8, 4, 2, 1”. This will then give us, 8+4+2+1=15.


Basic Addition

Much like the decimal system, binary numbers can be added together. For this example the binary numbers 0110 and 0010 are going to be used and added.

Eights Fours Twos Ones Total
Binary 0 1 1 0 6
Decimal 0 4 2 0 6


Eights Fours Twos Ones Total
Binary 0 0 1 0 2
Decimal 0 0 2 0 2


Thus by using decimal addition, 4+2+2=8, the value of the addition of two binary numbers can be determined as 8.