3 Attachment(s)
Convert A Number From Binary (Base 2) Numbering to Decimal (Base 10)
Me being the computer nerd I am, I decided to combine my love of math and love of computers to come up with a single formula that converts a number from base 2 (binary) numbering to base 10 (decimal) numbering.
There is one thing I would like to note about this formula. Computers think in 8-bit binary and this formula is meant to be used with the binary numbering system. True binary numbering means thats 1101000101110101 is a valid number (53,621). In 8-bit binary it would break into separate 8-digit sections (bytes) like this: 11010001 01110101. These would represent two separate values (209 and 117) instead of just one.
If anyone has any suggestions on otherways to accomplish this or any imput to add, I would love to hear it.
EDIT: I uploaded 2 .DOCs. One is a full explanation of the binary formula and the other is an explanation of how to isolate a digit in a number if you are given its position in the number.
x = Number in binary
n = Length of that number (how many digits are in it)
http://www.vbforums.com/attachment.p...id=43636&stc=1
Re: Convert A Number From Binary (Base 2) Numbering to Decimal (Base 10)
As in a formula that performs the operation without a LOOP?
Without "AND" masking?
Without "DIVIDE by Power of 2" bitshifting?
Re: Convert A Number From Binary (Base 2) Numbering to Decimal (Base 10)
Wait, were those questions? Yes it is a formula that does it without those things? I don't understand why you asked those things... But okay. :)
I guess it does kind of involve a loop because of the use sigma.
Re: Convert A Number From Binary (Base 2) Numbering to Decimal (Base 10)
Yes they were questions - it was early this morning when I read your post :)
I've been doing binary/bit manipulation for so long in VB (and other BASICS) that I cannot imagine a single formula to do what I've always done with loops and logic - can't wait to see what you come up with ;)
Re: Convert A Number From Binary (Base 2) Numbering to Decimal (Base 10)
I think you misunderstand. I posted the formula in the first post. It does involve a "loop" because of the sigma notation. There is no way to do it otherwise. Bitshifting might be faster for a computer though to avoid the floating point math.
NOTE: The brackets that look like this: [ ] but without the top part of the hook mean int().
Re: Convert A Number From Binary (Base 2) Numbering to Decimal (Base 10)
That's a pretty neat way to do the conversion! :thumb:
Re: Convert A Number From Binary (Base 2) Numbering to Decimal (Base 10)
I added 2 .DOCs that are explanations of the formula. I wrote them up for my own use and I thought I might post them here. Enjoy! :)