BitExtract: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
 (Created page with "{{Server client function}} {{Needs_Example}} __NOTOC__ {{New feature/item|3.0132|1.3.2|5340| This function returns the unsigned number formed by the bits field to field + width -...")  | 
				No edit summary  | 
				||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{  | {{Shared function}}  | ||
__NOTOC__  | __NOTOC__  | ||
{{New feature/item|3.0132|1.3.2|5340|  | {{New feature/item|3.0132|1.3.2|5340|  | ||
| Line 8: | Line 7: | ||
==Syntax==  | ==Syntax==  | ||
<syntaxhighlight lang="lua">  | <syntaxhighlight lang="lua">  | ||
uint bitExtract ( uint var, int field,   | uint bitExtract ( uint var, int field [, int width = 1 ] )  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
| Line 21: | Line 20: | ||
==Example==  | ==Example==  | ||
<syntaxhighlight lang="lua">  | <syntaxhighlight lang="lua">  | ||
function getColorAlpha(color)  | |||
   return bitExtract(color,24,8) -- return bits 24-32 ( the alpha, http://en.wikipedia.org/wiki/RGBA_color_space )   | |||
end  | |||
</syntaxhighlight>  | </syntaxhighlight>  | ||
==See Also==  | ==See Also==  | ||
{{Bit_functions}}  | {{Bit_functions}}  | ||
Latest revision as of 12:35, 20 September 2021
This function returns the unsigned number formed by the bits field to field + width - 1 (range: 0-31).
Syntax
uint bitExtract ( uint var, int field [, int width = 1 ] )
Required arguments
- var: The value
 - field: The field number
 - width: Number of bits to extract
 
Returns
Returns the extracted value/bit sequence.
Example
function getColorAlpha(color) return bitExtract(color,24,8) -- return bits 24-32 ( the alpha, http://en.wikipedia.org/wiki/RGBA_color_space ) end