J, 19 bytes
Monadic verb taking the number on the right and spitting out the container size. There are a couple of equivalent ways of writing it so I've included both.
2^2(>.+1=>.)@^.#@#:
2^s+1=s=.2>.@^.#@#:
Explained by explosion:
2^2(>.+1=>.)@^.#@#: NB. takes one argument on the right...
#: NB. write it in binary
#@ NB. length (i.e. how many bits did that take?)
2 ^. NB. log base 2 of that
(>. )@ NB. ceiling
+1=>. NB. +1 if needed (since no container is two bits wide)
2^ NB. base 2 exponential
What's cool is we see two different ways of taking log base 2 in J. The first is the obvious 2^.
, which is a numerical logarithm. The second is #@#:
, which can be read as "length of base-2 representation". This is almost equivalent to one-plus-floor-of-log-base-2, except that #:0
is the one-element list 0
, which is exactly what we want. This beats 1+2<.@^.1&>.
by 8 bytes.
In use at the REPL:
f =: 2^2(>.+1=>.)@^.#@#:
f 131313
32
f 34359750709
64
(,.f"0) 0 1 2 15 16 123 260
0 1
1 1
2 4
15 4
16 8
123 8
260 16
Old, overly clever 20 byte solution.
2&^.(>.+1=>.&.)@#@#: NB. takes one argument on the right...
#@#: NB. how many bits
2&^. NB. log base 2 of that
>. NB. ceiling
+1=>. NB. +1 if needed (since no container is two bits wide)
( &.) NB. undo log base 2
2
was an output too... \$\endgroup\$