Reading and writing numbers in binary seems to be difficult, but it isn't. Although useless, but a cool skill to have. It's used to make puzzles or make things complex unnecessarily.
a) Reading and writing numbers in binary.
for converting any number in decimal, to binary divide the number by 2, and take the remainders. For instance, you have a number, say 37 and you want to write in binary.
2 37
18-1
9 -0
4 -1
2 -0
1 -0
the quotient of each step is written under the number and the corresponding remainders in front of them. Now just take the last quotient and all the remainders in the order from bottom to top.
The value of 37 in binary will be: 100101
This method works for every base, just replace the 2 (divisor) by any number (the base in which you want to convert the decimal number into). For example if I want to convert any number in base 8, I'll divide it by 8 and then repeat the same process of taking the last quotient and all the remainders.
Now in order to read in binary, let's say 100101 is something written in binary. If we want to read it as a number in decimal number system. We'll take the sum of each digit multiplied by its positional value ( 2^0 to 2^(n-1)) for n digits. Start from the left.
1*(2^5) + 0*(2^4) + 0*(2^3) + a*(2^2) + 0*(2^1) + 1*(2^0)= 37
This method also works for other bases, if you have a number in octal, say 3472 repeat the same process, just replace the 2s with 8s. You'll get the value in decimal number system.
b) Now we'll move towards the interesting part, writing and reading alphabets in binary. For this, you need to know that a character takes one byte of space, and one byte has eight bits in it. And 1 bit contains either a 0 or a 1. For the alphabets and some other characters including space ( their is a representation for empty space in eight bits), there is a special chart which specifies the values of each alphabet, Its name is American standard chart for information exchange (ASCII). It was developed by a group of Americans. It allocated the values form 65 to 90 from A-Z (upper case) and values from 97 to 122 from a-z (lower case). As one character takes 8 bits (1 byte). The following technique is to be followed
F: 01000110 f : 01100110
( 6 in binary is 110 , it takes three bits, but we have to compensate it in five bits, so the rest of the bits will be zero, that's how it works)
If the first three bits are other than 010 and 011, then they are not alphabets, they'll probably be some other characters. You can refer the ASCII table, its available on google images easily.
Now comes reading in binary, for example we have something written as 01100011011000010110011101100101
just divide these into groups of eight bits,
01100011: first five bits from the left say, 3 which is lower case C i.e. 'c' (because of 011)
01100001: first five bits from the right say 1, which is a (lower case).
01100111: 11 which is k.
01100101: 5, which is e
so we have 'cake'.
Can you write your name in binary now? Give it a try.
a) Reading and writing numbers in binary.
for converting any number in decimal, to binary divide the number by 2, and take the remainders. For instance, you have a number, say 37 and you want to write in binary.
2 37
18-1
9 -0
4 -1
2 -0
1 -0
the quotient of each step is written under the number and the corresponding remainders in front of them. Now just take the last quotient and all the remainders in the order from bottom to top.
The value of 37 in binary will be: 100101
This method works for every base, just replace the 2 (divisor) by any number (the base in which you want to convert the decimal number into). For example if I want to convert any number in base 8, I'll divide it by 8 and then repeat the same process of taking the last quotient and all the remainders.
Now in order to read in binary, let's say 100101 is something written in binary. If we want to read it as a number in decimal number system. We'll take the sum of each digit multiplied by its positional value ( 2^0 to 2^(n-1)) for n digits. Start from the left.
1*(2^5) + 0*(2^4) + 0*(2^3) + a*(2^2) + 0*(2^1) + 1*(2^0)= 37
This method also works for other bases, if you have a number in octal, say 3472 repeat the same process, just replace the 2s with 8s. You'll get the value in decimal number system.
b) Now we'll move towards the interesting part, writing and reading alphabets in binary. For this, you need to know that a character takes one byte of space, and one byte has eight bits in it. And 1 bit contains either a 0 or a 1. For the alphabets and some other characters including space ( their is a representation for empty space in eight bits), there is a special chart which specifies the values of each alphabet, Its name is American standard chart for information exchange (ASCII). It was developed by a group of Americans. It allocated the values form 65 to 90 from A-Z (upper case) and values from 97 to 122 from a-z (lower case). As one character takes 8 bits (1 byte). The following technique is to be followed
- Starting from the right, fist three bits will be 011 for lower case alphabets
- And 010 for upper case alphabets
- Now comes the part where those Americans were clever, they said: 1 to 'A', both upper and lower case.
2 to 'B', both upper and lower case.
3 to 'C', both upper and lower case.
And so on.. We know how to write numbers in binary, so now it'd be easy for us. Let's consider the following examples.
F: 01000110 f : 01100110
( 6 in binary is 110 , it takes three bits, but we have to compensate it in five bits, so the rest of the bits will be zero, that's how it works)
If the first three bits are other than 010 and 011, then they are not alphabets, they'll probably be some other characters. You can refer the ASCII table, its available on google images easily.
Now comes reading in binary, for example we have something written as 01100011011000010110011101100101
just divide these into groups of eight bits,
01100011: first five bits from the left say, 3 which is lower case C i.e. 'c' (because of 011)
01100001: first five bits from the right say 1, which is a (lower case).
01100111: 11 which is k.
01100101: 5, which is e
so we have 'cake'.
Can you write your name in binary now? Give it a try.
No comments:
Post a Comment