Binary to Decimal
Working from the least-significant bit, the positional values are 1, 2, 4, 8, 16, 32, 64 and 128 (each more significant bit doubles the value of the preceding bit). If the corresponding bit is set, add that value to an accumulator initialised to zero.
Decimal to Binary
Repeatedly divide the decimal value by 2 and take the remainder (which can only be 0 or 1). Each division determines the value of the next most significant bit, starting with the least significant bit.
Chat with our AI personalities
Binary code is a code used to instruct computers what to do. It is not something that converts to English in a direct fashion, although you can say in English what the binary code is commanding - if you really understand the binary.
There are code convertors on line that can provide some basic interpretation. However, they cannot always 100% deal with all binary code. These will allow you to cut and past in code and convert to ASCII if they find an equated code
Add enough zeroes to the start of the binary string to make the length a multiple of 4.
Translate four characters at a time to a single hex character.
If the characters are 0000, the hex character is 0
If the characters are 0001, the hex character is 1
If the characters are 0010, the hex character is 2
If the characters are 0011, the hex character is 3
If the characters are 0100, the hex character is 4
If the characters are 0101, the hex character is 5
If the characters are 0110, the hex character is 6
If the characters are 0111, the hex character is 7
If the characters are 1000, the hex character is 8
If the characters are 1001, the hex character is 9
If the characters are 1010, the hex character is A
If the characters are 1011, the hex character is B
If the characters are 1100, the hex character is C
If the characters are 1101, the hex character is D
If the characters are 1110, the hex character is E
If the characters are 1111, the hex character is F
Add 0x at the left of all the hex characters and terminate the ASCIIZ string with a zero character.
Converting binary to decimal is done by taking each binary digit and multiplying it by its place value in the binary system. In the binary system, the place value of each digit is twice that of the digit to its right; the place value columns in binary, from the right hand end, are 1, 2, 4, 8, 16, 32, ... (just like in the decimal system they are ten times: 1, 10, 100, 10000, ...).
example:
11001012 = 1 x 64 + 1 x 32 + 0 x 16 + 0 x 8+ 1 x 4 + 0 x 2 +1 x 1
= 64 + 32 + 4 + 1
= 10110
To convert a decimal number to binary:
example:
10110 to binary:
101 ÷ 2 = 50 r 1
50 ÷ 2 = 25 r 0
25 ÷ 2 = 12 r 1
12 ÷ 2 = 6 r 0
6 ÷ 2 = 3 r 0
3 ÷ 2 = 1 r 1
1 ÷ 2 = 0 r 1
⇒ 10110 = 11001012
These methods can be used for conversion between any base and decimal base and vice-versa:
In converting to decimal, the place value columns are the base times the next column, eg converting octal (base 8) to decimal, each column is 8 times the next column; from the right hand end the place value column multipliers are 1, 8, 82 = 8 x 8 = 64, 83 = 64 x 8 = 512, 84 = 512 x 8 = 4096, etc.
In converting from decimal, divide by the new base10 (eg for octal (base 8), teh divisor is 8) noting the remainders, reversing them at the end.
example:
3458 = 3 x 82 + 4 x 8 + 5 = 22910
229 ÷ 8 = 28 r 5
28 ÷ 8 = 3 r 4
3 ÷ 8 = 0 r 3
⇒ 22910 = 3458
You can use the methods toUpperCase & toLowerCase to convert Strings to any case you want.
http://www.epa.gov/ttn/chief/ap42/ch07/final/c07s01.pdf page 56
[ string toupper $str ] or [ string tolower $str ]
Hard work.
lakshmikanth