4
$\begingroup$

I'm looking for a function $f$ that would give me the following results :

For any $x$ such as $ x \in \mathbb {N^*}, x>0 $

$f(x) = 1 $ when $1\leq x < 10$

$f(x) = 2 $ when $10\leq x < 100$

$f(x) = 3 $ when $100\leq x < 1000$

and so on ...

So far , I have tried the floor function with no success.

$\endgroup$
9
$\begingroup$

$$\lfloor \log_{10}(n) \rfloor + 1$$

$\endgroup$
  • $\begingroup$ Just clever. Thanks ;) $\endgroup$ – Stephan Jul 8 '13 at 12:30
  • $\begingroup$ Note this is fundamental to computing. To store the number 4294967295, you need $\lfloor\log_{2}(4294967295)\rfloor + 1 = 32$ bits. $\endgroup$ – BoppreH Jul 8 '13 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.