/* * Simplest way to use OddBases class. */ // Create instance $ob = new OddBases; // default is 32 // Convert decimal to base 24 print ( $ob->dec2base(12345) . "\n"); // Convert base 24 to decimal print ( $ob->base2dec('XLK') . "\n");
This was written because of a desire to write it following an interest in messing around was converting decimal to various other bases (similar to why ZPiTime was written).
Bases available: 10, 15, 24, 26, 32, 36, 54, 62. Add your own easily, or rearrange the ones already there.
/* * Simplest way to use OddBases class. */ // Create instance using base 24 $ob = new OddBases(24); // Convert decimal to base print( $ob->dec2base(1234567890) ); // Convert base to decimal print( $ob->base2dec('GMBCDAU') );
<?php /* * Need to load OddBases */ require "oddbases.php"; /* * Set voucher value and number. */ $value = 10; $number = 1; /* * Create new instance. * Base 32 has been chosen as it removes characters * 0 (zero), 1 (one), I (i), and O (o) which may be * confused depending on font face used. */ $ob = new OddBases(32); /* * Do a little math on the voucher value * and voucher number. This is done to ensure * both values when converted are 4 characters long. * * $10 become 912578 */ $v_value = ($value + 912577) - ( ($value / 10) * 9); /* * 1 becomes 775220 */ $v_number = $number + 775219; /* * Product of value and number is 707448717159 */ $sec_value = ($v_value * $v_number) - 1; /* * Now convert from decimal number to base 32. */ /* * 912578 becomes VV84 */ $voucher_value = $ob->dec2base($v_value); /* * 775220 becomes RP3N */ $voucher_id = $ob->dec2base($v_number); /* * 707448717159 becomes NLVMPHV9 */ $security_code = $ob->dec2base($sec_value); /* * Join the value above together. * $uid_tmp = VV84NLVMPHV9RP3N */ $uid_tmp = $voucher_value . $security_code . $voucher_id; /* * Add hyphens into the above code to make it more readable * VV84-NLVM-PHV9-RP3N */ $voucher_uid = implode( str_split( $uid_tmp, 4), "-"); print $voucher_uid . "\n";
Recently I designed a voucher for House of Cloth, and wanted to give each voucher a unique ID. Starting at 1 (0001 or V0001) and counting up was one option, but being such a simple thing, I decided to play around with OddBases.
Each voucher was to get a code in the form of VVVV-SSSS-SSSS-NNNN, where VVVV was the value of the voucher, NNNN was the number of the voucher, and SSSS-SSSS was the product of VVVV * NNNN. Any voucher ID (e.g. A2QQ-UK4L-N4B8-V3D4) can be checked to see if it is valid.