1

It has been awhile, and I know this is very basic, but if someone would help me just get this, I know I can start retraining my brain. Basically it is this. I have :

number of digits x

position of digit y

value of digit z

so, iterating through the digits (from left to right) I want to add the product of each value and 2^y-1.

Not sure how clear the question is. I can almost see the equation in my mind, but it has been so long.

Thanks.

  • Write down a 3 digit number. What would your expression look like? try it for a few 3 digit numbers. Try it for a 4 digit number. Try it for an x digit number. – Paul Nov 30 '16 at 10:43
  • well, in the case of a binary number 1011 = (1x2^3) + (0x2^2) + (1x2^1) + (1x2^0) - but, it doesn't have to be binary, 2 could be a variable that represents a base. – andrewthecoder Nov 30 '16 at 10:47
  • writing the program is no problem... expressing it as a mathematical equation is proving to be difficult (though, I know this is actually pretty simple) – andrewthecoder Nov 30 '16 at 10:50

1 Answers1

1

Oh, so you wanted:

$$\sum_{y = 1}^x z_y2^{y-1}$$

where y is the position of digit from the right (righmost = position $1$), or

$$\sum_{y = 1}^x z_{x-y+1}2^{y-1}$$

where y is the position of digit from the left (leftmost = position $1$), which is the same as

$$\sum_{y = 1}^x z_{y}2^{x-y}$$

(if you want make the sum from the left - most significant digit with position $1$ - to the right), or - without $\sum$ symbol -

$$z_{1}2^{x-1} + z_{2}2^{x-2} + \dots + z_{x}2^{0}$$

MarianD
  • 2,953