0

So I came across this post on stackoverflow which discussed the ranges of integer variables in C++. And the last point of the top-voted response was the unsigned long long int which apparently ranges from 0 to 18,446,744,073,709,551,615 (18.5 quintillion?). But that response did not mention what that would be equivalent to in bytes... Now I realize that there is obviously numerous other methods to figure this out, but what popped in my mind as a first thought is this:

$$\sum_{n=0}^{x}2^n = 18,446,744,073,709,551,615$$

Where x is the number of bits - 1. How would one go on about solving an equation like this? Sorry if it's something obvious, but no particular approach is coming to mind.

I already know that it's 8 bytes(x = 63)--the real topic here is equations that involve the Sigma Notation, and are they actually often seen in any fields of maths?

  • 1
    One way is to use the closed-form for the geometric series, namely for $r\neq 1$, $\sum_{n=0}^m r^n = (1-r^{m+1})/(1-r)$. Can you try it from here? – Integrand Jul 08 '20 at 22:26
  • Definitely does the trick! Simplifies to an easy equation solvable using logarithms. Interested in seeing other methods haha. Might have to do the research on my own though, not sure what this website's policies are on questions that have already been solved... – nourgaser2012 Jul 08 '20 at 22:36
  • Take $\log_2$; round – Integrand Jul 08 '20 at 22:37

2 Answers2

2

Any scientific hand-held calculator will give you the answer: as $$\sum_{n=0}^x2^n=2^{x+1}-1,$$ you only have to solve $$x+1=\log_2(18\,446\,744\,073\,709\,551\,616)=64.$$

Bernard
  • 175,478
0

You can use the finite geometric series formula

$$\sum_{n=0}^N x^n = \frac{1-x^{N+1}}{1-x}$$

In this case this has a simple form $2^{N+1}-1$, so then the equation is easily solved by taking logarithms.

Basel J.
  • 1,063