Writing general equations.

aCynic2

Senior member
Apr 28, 2007
710
0
0
I has been a while since I took a math class and I don't have any of my book anymore. I'm documenting a base number system for precise astronomical measurements on a computer for a game I'm writing, but I want to make sure I'm writing it properly. Here is what I'm thinking is the general equation for converting from base b to base 10 (decimal):

(Unfortunately, this %&*#!@ forum software doesn't preserve formatting):

NOTE: NX = N sub X (for indexing)

N sub X = (0 to b-1)
Where b is the base of the number system, so that in a base 10 system, b-1 = 9.

N0b^0 + N1b^1 + N2b^2 + N3b^3 +...+ N(n+1)b^(n+1) = base 10 num


I hope this comes across as sane.:)

One of the things I'm wondering is: Should the last term be n+1 or n-1?

I've seen n-1 quite a bit, but I just can't think if it applies here.
 

TuxDave

Lifer
Oct 8, 2002
10,571
3
71
If n represents the number of digits in the base b number, and N0 is the least significant digit then you stop at n-1. I want to also note, why you have N sub X with X stopping at b-1?

Editing for Clarification

So for simplicity, let's use binary which uses a base 2 system (b = 2) and the digits can ONLY be 0 or 1.

If my binary number was say... 10110, N4 = 1, N3 = 0, N2 = 1, N1 = 1, N0=0. So we see that X can exceed b-1 or 1 in this case. X just represents the digit's place.

So to answer your question

Here's the general equation.

x = Number of digits in base b that you want to convert
Nsub0 = Least significant digit in the number N
Nsubx = Digit x in the number N

Nsub0*b^0+Nsub1*b^1+Nsub2*b^2...(Nsubx-1)*b^(x-1)