What is binary?
Binary literally means, comprised of two parts.
At the very core, a computer is a large collection of transistors or “switches”. Each transistor can be in one of two states
High or Low current
This is represented by the numbers 1 (on/high) and 0 (off/low). You may notice this system used on various house hold appliances, ie: a kettle or Hoover switch.
Binary is what is known as a Base-2 number system, as it only uses the two values 1 and 0 and uses what is known as Boolean Logic. In contrast, decimal is Base-10 as it uses the values 0 1 2 3 4 5 6 7 8 and 9.
A computer stores all data in binary as a sequence of 1’s and 0’s known as Bits. For example, the letter “A” is stored as 01000001.
How does a computer deal with numbers higher than 1?
By taking 8 bits at a time, we can form what is known as a Byte (half a byte, 4 bits, being a nibble). By using 8 bits we can form any number between 0 and 255. This may still seem a bit confusing, however, read on and it should become clearer.
Converting Between Decimal and Binary
As binary is a base-2 system each leftmost bit is worth double that of the bit to its right, like so. (bare in mind a bit can be 1 or 0, for explanation purposes all bits are set to 1 here)
| BIT | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| VALUES | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Lets say for example we wanted to represent the number 23 in binary. What we would need to do is find out which values would add up to make the number 23. The easiest way of doing this is to find the values that ARENT used to make 23. Its worth noting that as binary is a Base-2 system it can also be used in Boolean logic, boolean being two statements, either TRUEor FALSE.
128 Goes into 23 ? False [or 0]
64 Goes into 23 ? 0
32 Goes into 23 ? 0
16 Goes into 23 ? True [or 1]
We now take the remaining value. 23-16=7
8 Goes into 7 ? 0
4 Goes into 7 ? 1
And again we take the remaining value. 7-4=3
2 Goes into 3 ? 1
Once again taking the remaining value. 3-2=1
1 Goes into 1 ? 1
So now we take each binary value, starting with the top value of 128, to form :
23 in Decimal = 00010111 in Binary.
To Check this we can simply reverse the process by adding each value together:
| BIT | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 1 |
| VALUE | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
16 + 4 + 2 + 1 = 23
Numbers Higher than 255
Now thats all good and well for numbers between 0-255. The highest number posible being 255 as if all bits are set to 1 you would add all 8 values together forming 255. So what about numbers above 255? Well you would use the same process just adding a new 8bits or “byte” to the beginning of the first byte. Remembering that each leftmost value is double the value to its
right, the highest possible number now will be 65,535. When two bytes are joined together forming 16bits, we call this a binary “word“.
How About Letters?
Its important to note that a letter is only a human representation of a binary sequence. With that said, the letter “a” is just a representation of the decimal value 97. (Try entering the ascii code 97 into a text editor by pressing Alt+097).
So now we have established that each letter or ascii character is infact a number, its simply a case of working out the binary value for that number. So using the letter “a” as a basis, we can now do the math. (remembering to work on the remainder).
| a = 97 | ||||
|
97 = |
||||
| VALUE | Goes Into | VALUE/REMAINDER | TRUE/FALSE | |
| 128 | Goes Into | 97 ? | 0 | |
| 64 | Goes Into | 97 ? | 1 | |
| 32 | Goes Into | 33 ? | 1 | |
| 16 | Goes Into | 1 ? | 0 | |
| 8 | Goes Into | 1 ? | 0 | |
| 4 | Goes Into | 1 ? | 0 | |
| 2 | Goes Into | 1 ? | 0 | |
| 1 | Goes Into | 1 ? | 1 | |
Therefore : a = 97 in decimal or 01100001 in binary.
Now you maybe wondering if 97 = 01100001 and “a” = 01100001, then how does the computer know whether your working with a number or a character. Well the easy answer is that it is stated in the programming of the software as either the variable INT (integer or number) or CHAR (character).
If you think you have grasped the idea of Binary, try some of the questions below.
Excercises
What is the Binary Representation of the Number : 128
What is the Binary Representation of the Number : 15
What is the Binary Representation of the Number : 63
What is the character represented by the binary : 00101010
(Note: you may need an ASCII code chart for the decimal values)
What is the binary value of the character : f
What is the binary value of the character : )
For the answers, highlight the blank area below by holding your left mouse button and dragging the pointer from top-left to bottom-right in the empty space below.
128 = 1000000
15 = 00001111
63 = 00111111
00101010 = *
f = 102 = 01100110
) = 41 = 00101001
