+ 1

How to convert binary into numbers?

I know at numbers can be converted to binary by division by 2. But what about binary to number?

11th Feb 2017, 12:57 PM
Daniel Fernandes
Daniel Fernandes - avatar
8 Respostas
+ 9
In JavaScript, var myBinary = "10100101" ; document.write(parseInt(myBinary, 2))
11th Feb 2017, 2:12 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 8
on paper it's the same way as I explained. from right to left: 2^0, 2^1, 2^2, 2^3, ... multiplied by either 1 or 0. 100110 = 1*2^5 + 0*2^4 + 0*2^3 + 1*2^2 + 1*2^1 + 0*2^0
11th Feb 2017, 4:40 PM
Mario L.
Mario L. - avatar
+ 4
put the digits of the binary number in an array and reverse it. now loop through that array and add digit_in_position * 2 ^ position_of_digit to the result.
11th Feb 2017, 1:06 PM
Mario L.
Mario L. - avatar
+ 3
thanks
11th Feb 2017, 4:42 PM
Daniel Fernandes
Daniel Fernandes - avatar
+ 2
well I want to do it on a piece of paper. is it possible that way?
11th Feb 2017, 3:25 PM
Daniel Fernandes
Daniel Fernandes - avatar
+ 1
Revised and Fixed 😊 there is a basic table for this, as Mario said it is the powers of 2 since it is binary. the table consists of 8 columns and 3 (once you have memorized, 2) rows. these are filled with. e. g. 01011001 '2 to the power of' represented by "~" ~0. | ~1. | ~2. | ~3. | ~4. | ~5. | ~6 | ~7. | 1. | 2. | 4. | 8. | 16 | 32 | 64. | 128| the third row being the binary number, as I said earlier you may only need one of these rows as they are just for example sake. 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | ⚠ This is backwards now add the corresponding columns. 2 + 8 + 16 + 128 = 154 (if my math is correct) <- wrong 64 + 16 + 8 + 1 = 89 (once table is fixed) this can be done in reverse to work out the binary for a number. 78 = 0 (can't subtract 128 with a whole number remainder) 1 (can subtract 64 with 14 remainder) 0 (can't subtract 32 from 14) 0 (cant sub 16) 1 (sub 8 with 6 left) 1 (can sub 4 r 2) 1 (can sub 2, 0 remainder) 0 (can't sub 1) answer is 01001110 = 78 however dividing by 2 works best I. e. 186 = x / 2 = 93 r 0 = 46 r 1 = 23 r 0 = 11 r 1 = 5 r 1 = 2 r 1 = 1 r 0 = 0 r 1 notice that the remainder is ignored. because it is from highest to lowest you have to interpret backwards so instead of 01011101 it is 10111010 as it has to be in the correct order. if you are after letters you will have to refer to an ASCII conversation table with the relating base 10 number but they may have the base 2 known as binary converted directly to letters. I hope this makes sense and doesn't confuse to many people. cheers, Kurios
12th Feb 2017, 7:17 AM
Kurios Gaming
Kurios Gaming - avatar
0
I have realised my example is backwards I'll redo the table to correct my mistake. | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | so this example is actually 64 + 16 + 8 + 1 = 89 sorry for the inconvenience, kurios
12th Feb 2017, 7:32 AM
Kurios Gaming
Kurios Gaming - avatar
0
As in Java: while(NumberInput!=0) { digit = n%10; number/= 10; Decimalvalue = Math.pow(2,I)*d; count++; } The decimal value will be (The data stored in Decimalvalue) 😃
12th Feb 2017, 5:23 PM
Avi
Avi - avatar