Binary Notation

Binary is a format of ‘1s’ and ‘0s’ that when combined represent information that a computer can read. This information is interpreted by the computer’s processors as a high or low voltage. There are different types of binary notation.  The three most common binary encoding are unsigned, two’s-complement, and floating-point.  I will not go into too much info in this posting on the encodings, but when I have time I will later go into more on two’s-complement and unsigned because they are important things to think about when coding.  The importance of these things comes from the fact that carelessness can accidently cause stack overflowing or malicious intent can intentionally “smash” the stack.  For now, unsigned means a number greater than or equal to 0, two’s-complement or signed is used to represent negative and positive numbers, and floating-point is a scientific notation for real numbers.  These encoding are represented in base-2 where 0 is equal to ‘off’ and 1 is equal to ‘on’.

Example:

Let’s try to convert the number 42 to binary. I think the easiest way to work in binary is to find a power of two that is a little bigger than the number we need.  In this example 2^6 = 64 is bigger than 42. So I start by building a block of binary that are set to ‘0’ or ‘off’ to work with:

Bit(on/off): 0 0 0 0 0 0 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Once we have our block of binary, we start from left to right and put a ‘1’ for the values we need to equal up to 42.

Bit(on/off): 0 1 0 0 0 0 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Since we turned ‘on’ the value of 32, we can subtract 42 -32 which gives us our next value to look for which is ten. Ten is not a value in our block of binary, but eight is so we turn on the value again by putting a ‘1’.

Bit(on/off): 0 1 0 1 0 0 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Again we subtract ten from eight which gives us our next value of 1wo. Luckily two is a value in our block.

Bit(on/off): 0 1 0 1 0 1 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

This makes our binary value of 42 as 0101010.  If you search online, there are many ways to convert to binary and back. In fact, there are sites and apps that will do it for you. I encourage anyone learning to convert to and from binary to practice by hand before getting comfortable using an application. You will get a better understanding of how it works.

Practice/Game: http://forums.cisco.com/CertCom/game/binary_game_page.htm

Leave a comment