9 ms·
10 > 64, in QR codes
- gnabgib 3y agoUh... no. `6513249` as an integer is 3 bytes `0x636261`.. which in base 64 is `Y2Jh`.. 4 bytes (article lists in little endian, but so be it).. we've already switched from integer to string to type and support the premise.. base64 is clearly worse. And let's flag this as cherry picking, Base64 is always a multiple of 4 bytes, so `2` (1 byte as either an integer or string) in base 64 is `Ag==` (4 bytes).. so even /worse/. QR codes (like barcodes) were built with data in mind, supporting 4 types.. integers (numeric 0-9, use 3.3 bits ea).. "alphanumeric" (not really `[0-9A-Z$%*+-./:]`, use 5.5 bits ea), binary (0x00-0xff, use 8 bits ea), kanji (use 13 bits ea). As you move up the compression/data usage mostly gets worse. By incorrectly converting binary (0-255) to base64 (0-63) you waste 3 bits per element (8 bits {because the space is > "alphanumeric"} to hold 5 bits of data). This is a tale of not understanding encoding, and using the wrong tool for the job. Which the article further does by advocating for decimal instead of binary.. the example: `072685680885510189821994892577900638215789419258463239488533499278955911240512279111633336286737089008384293066931974311305533337894591404330656702603998035920596585517131555967430155259257402711671699276432408209151397638174974409842883898456527289026013404155725275860173673194594939` (in decimal, 285 bytes as a string, 950 bits in QR) can be `B9IiBlcmVoIHNlb2cgc3NlcmRkYSBzc2VuaXN1QiI6InNzZXJkZGFiIiwiZWRvYyBSUSB0bmVtbnJldm9HIFdTTiB0c2VUIjoiZW1hbmIiLCIxMjMxMjEiOiJkaWIiLCJzc2VuaXN1Yl85MWRpdm9jIjoidCJ7` (in base64, 158 bytes, 1264 bits in QR) but if done correctly, can be `07D2220657265682073656F672073736572646461207373656E69737542223A227373657264646162222C2265646F6320525120746E656D6E7265766F472057534E2074736554223A22656D616E62222C22313233313231223A22646962222C227373656E697375625F39316469766F63223A2274227` (in hex, 944 bits in QR)
- jepler 3y agoWhat I think you're overlooking here is the requirement that the data part also be "url-safe". If this requiement was not present, you'd be right that the binary encoding is better ("100% efficient") url-safe decimal: log2(10) * 3 / 10 = 99.7% url-safe alphanumeric: log2(39) * 2 / 11 = 96.1% efficient [39 out of 45 codes are URL-safe per article author] url-safe base64url: log2(64) / 8 = 75% efficient