Today computers use millions of bytes of memory, and decimal or hexadecimal notations get less and less informative.
Most human-readable formatting just display the number with the highest unit prefix. What about the rest?
I devised a notation that I use for myself, and since then, I'm often faced with re-implementing it in various languages. I thought I could share it, and that it make for a good case for code-golfing too.
- The program is given an integer as its input. It can be taken from a decimal or hexadecimal representation in a text file and then parsed, or from the "system innards".
- It should outputs a representation of that number somehow
- The limits are the system's limit. For practical purposes, assume 64 bits unsigned, so that the maximum number is 0xFFFFFFFFFFFFFFFF, and the unit suffixes will be k (kibi), M (mebi), G (gibi), T (tebi), P (pebi), E (exbi).
- zeros should be skipped. Example: 5G + 10k should be written 5G;10k, and not 5G;0M;10k;0
- It frequently happens, e.g. for memory ranges, that a number is just one less than a number with a nicer representation. For instance, 0xffff would be displayed as 63k;1023, though it is 64k minus 1. An exclamation mark denotes this, so that 0xffff should be displayed as !64k.
- 0 : 0
- 1023: !1k
- 1024: 1k
- 1025: 1k;1
- 4096: 4k
- 0x100000 : 1M
- 0xFFFFF : !1M
- 0x20000f : 2M;15
- 0x80003c00 : 2G;15k
- 0xFFFFFFFFFFFFFFFF : !16E
- For 32 bits users, use 0xFFFFFFFF, which is, as everybody knows, !4G.
- And 128 bits users can go up to... wait that's big! Anyway, feel free...