BitExtract: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m (Cosmetic syntax change) |
||
Line 7: | 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> | ||
Revision as of 10:25, 7 July 2014
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