As many of us have already been told, computers only understand two different bits of information, 1 and 0. However, an endless combination of 1s and 0s provides us with limitless information and computation capabilities.
The binary, or base 2, language is based on factorials of two. In any binary string, the furthest right number represents 2 to the 0 (or 1). The next number to the left, represents 2 to the power of 1 (or simply 2). The next number to the left represents 2 squared (or 4). This process continues on until we reach the furthest digit to the left. If the binary character in the given position is one, we add that value to the number. If the character is 0, we do not add the value.
For example, the binary number, 10011101b is equivalent to 128 + 16 + 8 + 4 + 1 or 157. The place values for an 8 bit number are 128, 64, 32, 16, 8, 4, 2, 1. We do not add the 2, 32 or 64 values as their positions are held by 0.
Each binary digit equals one bit. Four bits equal a nibble. Two nibbles (or 8 bits) is a byte. Current computing systems typically allow for up to 64 bits for any given number. The largest 64 bit number is somewhere around 9,223,372,036,854,776,000 (but not exactly).
Now imagine, converting a 64 bit binary number:
We can represent larger binary numbers using the hexadecimal system. Hexidecimal can serve as a shorthand for binary. Hexidecimal are a base 16 numbers. Each binary nibble (4 bits) is broken down into one character. The maximum number represented by any binary number is 2 to the nth – 1, where n represents the length of the binary string. So, the largest number that can be represented by a nibble is 15. In hexadecimal, we use the numeric characters to represent 0 – 9 and alpha characters A – F to represent 10 – 15 respectively.
So, using our previous example, 10011101b, which we earlier determined represented the decimal value of 157, we convert to a hexidecimal as follows:
- Break the binary number into nibbles: 1001 1101
- determine the decimal value of each nibble: 8 & 13
- Express in hexidecimal with the prefix of 0x: 0x8D
It is hardly worth converting this 8 bit binary number, but our 64 bit number above can be expressed as: 0xB777BEFDF875B83D. Although still long, it is still 47 digits smaller than its binary counter part (including prefix/suffix for both expressions).
In a upcomming post, I will explain how binary is used to express alpha characters and negative numbers.