Lasso Soft Inc. > Home

[lp_integer_toUnsigned]

Linklp_integer_toUnsigned
AuthorBil Corry
CategoryMath
Version8.x
LicensePublic Domain
Posted05 Dec 2005
Updated05 Dec 2005
More by this author...

Description

Returns the base10 unsigned integer value given a signed base10 integer.  The octet remains unchanged, only the decimal representation is converted.

Requires [lp_integer_bits], [lp_math_dectobin]

Sample Usage

lp_integer_toUnsigned: -93; // returns 163
'
'; lp_integer_toUnsigned: -1; // returns 255 '
'; lp_integer_toUnsigned: -128; // returns 128

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_integer_toUnsigned',
	-description='Returns the base10 unsigned integer value given a signed base10 integer.  The octet remains unchanged, only the decimal representation is converted.',
	-priority='replace',
	-required='signed',-copy;

	#signed = integer: #signed;

	if: #signed >= 0;
		return: #signed;
	else;
		local:'ibits' = (lp_integer_bits: (math_abs: #signed));
		local:'bits' = (math_ceil: (decimal:#ibits) / (decimal:8));
		if: #ibits % 8 == 0 && (lp_math_dectobin: 128)->(removetrailing:'0') & ->size > 1;
			#bits += 1;
		/if;
		#bits *= 8;

		return: (integer:(math_pow: 2, #bits)) + #signed;
	/if;

/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