I\'m looking for the most efficient way to calculate the minimum number of bytes needed to store an integer without losing precision.
e.g. int: 10 = 1 byte
You need exactly the log function
nb_bytes = floor(log(x)/log(256))+1 if you use log2, log2(256) == 8 so
floor(log2(x)/8)+1