Link | lp_math_binToHex |
Author | Bil Corry |
Category | Math |
Version | 8.x |
License | Public Domain |
Posted | 06 Dec 2005 |
Updated | 06 Dec 2005 |
More by this author... |
Returns a base16 string given a base2 string.
lp_math_bintohex: '1010101111001101'; // ABCD
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
[ define_tag:'lp_math_binToHex', -description='Returns a base16 string given a base2 string.', -priority='replace', -required='base2', -copy; // http://www.danbbs.dk/~erikoest/hex.htm local:'conversion' = (map: '0000' = '0', '0001' = '1', '0010' = '2', '0011' = '3', '0100' = '4', '0101' = '5', '0110' = '6', '0111' = '7', '1000' = '8', '1001' = '9', '1010' = 'A', '1011' = 'B', '1100' = 'C', '1101' = 'D', '1110' = 'E', '1111' = 'F' ); #base2 = string: #base2; local:'base16' = string; if: #base2->size % 4 > 0; #base2 = (lp_string_pad: #base2, (#base2->size + (4 - (#base2->size % 4))) ,'0'); /if; local:'ptr' = 1; loop: integer:(#base2->size / 4); #base16 += #conversion->(find: (#base2->(substring: #ptr, 4))); #ptr += 4; /loop; return: (lp_string_pad: #base16, 2, '0'); /define_tag; ]
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft