Lasso Soft Inc. > Home

[lp_integer_bits]

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

Description

Returns the number of bits the given integer is comprised of.

Requires [lp_math_log], [lp_integer_toUnsigned]

Sample Usage

loop: -from=-20, -to=20;
loop_count ' ';
lp_integer_bits: loop_count;
'
'; /loop;

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_bits',
	-description='Returns the number of bits the given integer is comprised of.',
	-priority='replace',
	-required='integer';
	if: (integer: #integer) < 0;
		return: (integer:(math_floor: (lp_math_log: lp_integer_toUnsigned:(integer:#integer), 2))) + 1;
	else: (integer: #integer) == 0;
		return: 1;
	else;
		return: (integer:(math_floor: (lp_math_log: (integer:#integer), 2))) + 1;
	/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