that is not giving me expected values. for example an int with a value anywhere from 0 to 255 should have a size of 1. from 256 to 65535 should have a size of 2. it appears that sys.getsizeof is returning memory usage information, which is bot what i want.
256**
n-1 should always give
n and is the highest value to do so. 256**
n should always give
n+1.
i have found a different method. i can repeat an integer divide (
// in Python3) on the number until it reaches 0. the count is the answer. but divide is slower than multiply so i think this is actually worse. another possibility is to change the multiply search to make increasingly faster steps by squaring (doubles the power) the when this exceeds the number in question, do a binary search of powers of 256 to narrow down the correct answer. IMHO, although Python is intended for tasks where ultimate speed of run time is not a requirement, use of best [known] algorithms is always a good thing for any application in any language. choice of application is part of the design step, although i have, for many projects, looped back to design.
i guess i misled by saying "store it". i meant to store just the numeric value itself in a sequence of bytes (not how much memory some engine uses). this would be the bytes you get from the .
to_bytes() method. the 1st argument is how many bytes you want which must be at least as many needed to store the numeric value (it raises OverflowError if the chosen amount is too small)
perhaps shift operations can do this better.