Logarithm of base 256.
How many bytes you need to store the 10**6 number? Use logarithm of base 256.
% python3 ... >>> import math >>> math.log(10**6, 256) 2.4914460711655217
Indeed, 2.5 bytes:
>>> hex(10**6) '0xf4240'
A tickler file or 43 Folders System is a collection of date-labeled file folders organized in a way that allows time-sensitive documents to be filed according to the future date on which each document needs action. Documents within the folders of a tickler file can be to-do lists, pending bills, unpaid invoices, travel tickets, hotel reservations, meeting information, birthday reminders, coupons, claim tickets, call-back notes, follow-up reminders, maintenance reminders, or any other papers that require future action. Each day, the folder having the current date is retrieved from the tickler file so that any documents within it may be acted on. Essentially, a tickler file provides a way to send a reminder to oneself in the future—"tickling" one's memory. ... 43 divisions In larger institutional uses, a tickler file would be chronological, with one section for each year or day, sometimes encompassing more than a century in as much detail as appropriate (especially for dates far in the future). A more common technique is to have index cards with forty-three dividers or a system with forty-three folders or two accordion files. The forty-three divisions come from the sum of two numbers, thirty-one and twelve, corresponding to the maximum thirty-one days in a Gregorian or Julian month and the twelve months in a year. Using folders, items scheduled for the current month are placed within the appropriate daily folder. Items which need to be done in a future month are placed in the corresponding monthly folder. Every day, the current daily folder is emptied and placed at the back of the set. At the start of a new month, the items for that month are removed from the month folder and placed in the corresponding daily folders.
( src )
GNU GMP library (for bignums) doesn't have logarithmic functions. But what can be used instead is a function that measures a length of a bignum for a specific base.
Let's see:
#include <stdio.h> #include <gmp.h> void main() { mpz_t x; mpz_init(x); mpz_set_ui(x, 1); mpz_mul_ui(x, x, 23456789); mpz_mul_ui(x, x, 876543210); mpz_mul_ui(x, x, 1234); mpz_mul_ui(x, x, 8765); gmp_printf("x=%Zd\n", x); gmp_printf("mpz_sizeinbase(x, 2)=%d\n", mpz_sizeinbase(x, 2)); gmp_printf("mpz_sizeinbase(x, 10)=%d\n", mpz_sizeinbase(x, 10)); mpz_clear(x); };
x=222386782399521958566900 mpz_sizeinbase(x, 2)=78 mpz_sizeinbase(x, 10)=24
We can check this in Python:
>>> import math >>> x=222386782399521958566900 >>> math.log(x,2) 77.5574172261662 >>> math.log(x,10) 23.347108971302386
So the output of the mpz_sizeinbase() is like ceil(log(x)) or (int)log(x) if you want:
>>> math.ceil(math.log(x,2)) 78 >>> math.ceil(math.log(x,10)) 24
Yes, sometimes you don't need very precise value of logarithmic function. Integer part would be enough.
Internally, GMP calculates bits of a number and then multiplies that value by log(2)/log(b) precomputed value, where b is 'destination' base:
/* Compute the number of digits in base for nbits bits, making sure the result is never too small. The two variants of the macro implement the same function; the GT2 variant below works just for bases > 2. */ #define DIGITS_IN_BASE_FROM_BITS(res, nbits, b) \ do { \ mp_limb_t _ph, _dummy; \ size_t _nbits = (nbits); \ umul_ppmm (_ph, _dummy, mp_bases[b].logb2, _nbits); \ _ph += (_dummy + _nbits < _dummy); \ res = _ph + 1; \ } while (0) #define DIGITS_IN_BASEGT2_FROM_BITS(res, nbits, b) \ do { \ mp_limb_t _ph, _dummy; \ size_t _nbits = (nbits); \ umul_ppmm (_ph, _dummy, mp_bases[b].logb2 + 1, _nbits); \ res = _ph + 1; \ } while (0)
( gmp-6.3.0/gmp-impl.h )
Remember serial number for Windows (or 'product key'). 5 groups of 5 characters.
I've forgot to mention also this. How many bits/bytes can be stored in such a 'product key'?
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux ... >>> possible_characters=26+10 >>> characters_total=25 >>> possible_characters**characters_total 808281277464764060643139600456536293376 >>> import math >>> math.log(possible_characters**characters_total,2) 129.24812503605781 >>> (math.log(possible_characters**characters_total,2))/8 16.156015629507227
~129 bits or ~16 bytes.
Some time ago (before 24-Mar-2025) there was Disqus JS script for comments. I dropped it --- it was so motley, distracting, animated, with too much ads. I never liked it. Also, comments didn't appeared correctly (Disqus was buggy). Also, my blog is too chamberlike --- not many people write comments here. So I decided to switch to the model I once had at least in 2020 --- send me your comments by email to blog at yurichev dot com (don't forget to include URL to this blog post) and I'll copy&paste it here manually.
Let's party like it's ~1993-1996, in this ultimate, radical and uncompromisingly primitive pre-web1.0-style blog and website.