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

Bitwise math/Introduction

From NetSec
Jump to: navigation, search
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.