Question: How can I find out the number of Bytes a certain integer number takes up to store?

E.g. for

* hexadecimal `\x00` - `\xff` (or decimal `0` - `255` = binary `0000 0000` - `1111 1111`) I'm looking to get 1 (Byte),
* hexadecimal `\x100` - `\xffff` (or decimal `256` - `65535` = binary `0000 0001 0000 0000` - `1111 1111 1111 1111`) would give me 2 (Bytes)

and so on.

Any clue for hexadecimal or decimal format as the input?

Answer: 
Unless you're dealing with an `array.array` or a `numpy.array` - the size always has object overhead. And since Python deals with BigInts naturally, it's really, really hard to tell...

```
>>> i = 5
>>> import sys
>>> sys.getsizeof(i)
24

```

So on a 64bit platform it requires 24 bytes to store what could be stored in 3 bits.

However, if you did,

```
>>> s = '\x05'
>>> sys.getsizeof(s)
38

```

So no, not really - you've got the memory-overhead of the definition of the `object` rather than raw storage...

If you then take:

```
>>> a = array.array('i', [3])
>>> a
array('i', [3])
>>> sys.getsizeof(a)
60L
>>> a = array.array('i', [3, 4, 5])
>>> sys.getsizeof(a)
68L

```

Then you get what would be called normal byte boundaries, etc.. etc... etc...

If you just want what "purely" should be stored - minus object overhead, then from 2.(6|7) you can use `some_int.bit_length()` (otherwise just bitshift it as other answers have shown) and then work from there
```
# Python 3

import math

nbr = 0xff                 # 255 defined in hexadecimal
nbr = "{0:b}".format(nbr)    # Transform the number into a string formated as bytes.

bit_length = len(nbr)      # Number of characters
byte_length = math.ceil( bit_length/8 ) # Get minimum number of bytes

```