note 37086 deleted from function.ord by sp

From: Date: Sun, 02 Nov 2003 22:47:29 +0000
Subject: note 37086 deleted from function.ord by sp
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59663@lists.php.net to get a copy of this message
Note Submitter: brian_le_mechant@tinyfrenchcompany.fr ---- Actually, this little operator is amazingly useful! It has many uses for base conversion, math and crypto work. Also, very useful for compression of sparse data. Especially if you want to compress and uncompress a bunch of codes to fit a smaller area, but cannot use pure binary representations for some reason. Otherwise, you can simply treat the string like an array of numbers. I use this to pack four variable status codes into a tiny character string for use with mysql. For example, to encode 384 different status codes into a database, one is caught by the lack of a varchar bigger than 256 but smaller than 1000 and also allowing text search. Simply start with 22* as a base, and then do binary math on the value using your formula: $sum = 33 + ($flag1 * 16)+($flag2*4)+(etc.); or, like me, use base4 math to pack more in. Thus with little effort, instead of $flags = "T?FX", I can represent all codes (notice they are multi-value) as easily parseable 1 character - which means I can pack 512 or 1024 codes in a tinytext! If you must stay in ASCII range, use just four sets of encoded flags per byte. note*: doesn't matter what you pick, use 32 or 33 if you don't want to take a chance on control codes. To restore them, just use ord to recover the digits, subtract the base number and use a lookup to put them back in your string or array for processing. Fast! My application needed quickly searchable way to check multiple warehouses for available space. Most had almost 400 locations (bays/shelves). I used codes F=full, E=empty, B=broken and R=reserved plus some others. By putting 2 locations in each byte this way, I could easily search for empty space in over 1000 sites!

« previous php.notes (#59663) next »