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: 
```
def byte_length(i):
    return (i.bit_length() + 7) // 8

```

Of course, as Jon Clements points out, this isn't the size of the actual `PyIntObject`, which has a PyObject header, and stores the value as a bignum in whatever way is easiest to deal with rather than most compact, and which you have to have at least one pointer (4 or 8 bytes) to on top of the actual object, and so on.

But this is the byte length of the number itself. It's almost certainly the most efficient answer, and probably also the easiest to read. 

Or is `ceil(i.bit_length() / 8.0)` more readable?
```
# 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

```