I'm not sure what sort of formula you're looking for. There's really only one way to do it, and that's to multiply successive powers of 2 by the bit representing it.
i.e.
if the function bit(n) returns the bit at position n, starting at 0 which would return the lowest bit (right-most when writing out the binary value), and the variable 'length' contains the number of bits,
x = 1;
for (y = 0; [while] y < length;y=y+1) {
total = total + bit(y) * x;
x = x * 2;
}
2006-07-17 12:56:05
·
answer #1
·
answered by lazwatson 3
·
0⤊
0⤋
You need to arrange the binary digits in a string starting with the least significant digit. Then assign a value to each digit starting with 1, then 2, 4, 8, 16, 32, etc. Add all the values where the associated digit is a 1 and do not add the digits value if the digit is a 0.
I hope you are not doing too many digits....
2006-07-17 12:53:15
·
answer #2
·
answered by rscanner 6
·
0⤊
0⤋
just remeber each digit in binary as you go from right to left equals twice the previous like this
11111111
the furthest right digit is 1 or zero if off
the next is 2 or zero if off
the next is 4 or zero if off
the next is 8 and so on
so 10101110 would be 174
i would convert the binary number to a string and work through it digit by digit backwards (right to left) just adding as you go.
here is some basic code that will convert for you, you'll have to put the binary number into "BinaryNumber$" and the output will be in the variable Decimal#
'-------start of code
a# = 1
For x% = Len(BinaryNumber$) to 1 step -1
If mid$(BinaryNumber$) , x%, 1) = "1" then
Decimal# = Decimal# + a#
end if
A#= A# * 2
next
2006-07-17 12:59:16
·
answer #3
·
answered by Anonymous
·
0⤊
0⤋
Since you are converting binary to decimal, I would assume you are working with computers, and so my answer would not be in the form of a formula, but in the form of a routine.
Using this approach, you can assign binary values to variables you create, and then use text manupulation of the binary value to decide which variables to add together.
A=1
B=2
C=4
D=8
E=16
F=32
G=64
H=128
10011010 = B+D+E+H
If you aren't doing it in a program, open up your Windows calculator, click on Bin for binary, type in your number, then click on Dec for decimal and you have your answer.
Happy converting!
2006-07-17 12:59:40
·
answer #4
·
answered by Anonymous
·
0⤊
0⤋
I don't think that there is a good way that you can convert binary to base 10 by just using an equation.
Here is some java script code you can use. You just create a blank text file on your desktop with a .js extension, paste the code into the file, and run in from your desktop.
binary = "111010001011101";
decimal = 0;
for(binaryLoop = 0; binaryLoop < binary.length; binaryLoop++)
if (binary.substr(binary.length - binaryLoop - 1,1) == "1")
decimal+=Math.pow(2, binaryLoop);
WshShell = WScript.createObject( "WScript.Shell");
WshShell.Popup(decimal);
2006-07-17 13:50:22
·
answer #5
·
answered by Michael M 6
·
0⤊
0⤋
This question just gave me a headache... and unfortunately, I do not have an answer for you.
2006-07-17 12:48:40
·
answer #6
·
answered by Anonymous
·
0⤊
0⤋
Try this website
http://www.csgnetwork.com/basexcnv.html
2006-07-17 12:52:40
·
answer #7
·
answered by Marianna 6
·
0⤊
0⤋