Lasso Soft Inc. > Home

[lp_string_radixprint]

Linklp_string_radixprint
AuthorBil Corry
CategoryString
Version8.x
LicensePublic Domain
Posted23 Jan 2006
Updated23 Jan 2006
More by this author...

Description

Returns binary, decimal and hexadecimal values for a given string or bytes.

Requires [lp_string_printf]

Sample Usage

'
\r\n';
lp_string_radixprint: 'This is a test. It is only a test. ?';
'
'; Returns: Binary | Hex | Dec | Chr ---------------------------------+----------+------------+---- 00000000000000000000000001010100 | 54 | 84 | T 00000000000000000000000001101000 | 68 | 104 | h 00000000000000000000000001101001 | 69 | 105 | i 00000000000000000000000001110011 | 73 | 115 | s 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001101001 | 69 | 105 | i 00000000000000000000000001110011 | 73 | 115 | s 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001100001 | 61 | 97 | a 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001110100 | 74 | 116 | t 00000000000000000000000001100101 | 65 | 101 | e 00000000000000000000000001110011 | 73 | 115 | s 00000000000000000000000001110100 | 74 | 116 | t 00000000000000000000000000101110 | 2E | 46 | . 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001001001 | 49 | 73 | I 00000000000000000000000001110100 | 74 | 116 | t 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001101001 | 69 | 105 | i 00000000000000000000000001110011 | 73 | 115 | s 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001101111 | 6F | 111 | o 00000000000000000000000001101110 | 6E | 110 | n 00000000000000000000000001101100 | 6C | 108 | l 00000000000000000000000001111001 | 79 | 121 | y 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001100001 | 61 | 97 | a 00000000000000000000000000100000 | 20 | 32 | 00000000000000000000000001110100 | 74 | 116 | t 00000000000000000000000001100101 | 65 | 101 | e 00000000000000000000000001110011 | 73 | 115 | s 00000000000000000000000001110100 | 74 | 116 | t 00000000000000000000000000101110 | 2E | 46 | .

Source Code

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_string_radixprint',
	-description='Returns binary, decimal and hexadecimal values for a given string or bytes.',
	-priority='replace',
	-required='string',-copy,
	-optional='encoding',
	-optional='bytes';

	if: !local_defined:'encoding';
		local:'encoding' = $__encoding__;
	/if;

	if: local_defined:'bytes'; // -bytes option
		if: #string->type == 'string';
			local:'bytes' = bytes;
			#bytes->(importstring: #string, #encoding);
			#string = #bytes;
		else: #string->type != 'bytes';
			#string = (bytes: #string);
		/if;
	else; // string
		if: #string->type == 'bytes';
			#string = #string->(exportstring: #encoding);
		else;
			#string = (string: #string);
		/if;
	/if;

	local:'return' = (lp_string_printf: '%-32s | %{8s | %{10s | %{s\r\n', 'Binary', 'Hex', 'Dec', 'Chr');
	#return += ('-' * 33) '+' ('-' * 10) '+' ('-' * 12) '+' ('-' * 4) '\r\n';
	iterate: #string, local:'char';
		#return += (lp_string_printf: '%{32.32b | %8x | %}10d | %{3c\r\n', #char, #char, #char, #char);
	/iterate;

	return: @('
' #return '
'); /define_tag; ]

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft