Hex
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Function: string hex(integer value);
Returns the hexadecimal nybbles of the signed integer value in order. Specifically returns the nybbles from most to least significant, starting with the first nonzero nybble, folding every nybble to lower case, and beginning with the nonnegative "0x" or the negative "-0x" prefix.
Parameters:
• integer | value | – | signed value to be expressed as signed hex |
Note: Results with eight nybbles begin always with one of the positive octal nybbles 1 2 3 4 5 6 7, never with a zero or non-octal nybble 0 8 9 a b c d e f.
Caution: This page was a work in progress as of 2007-10. The specification, the implementations, the demo, and the sample results may not yet be totally consistent.
Implementations
Easy To Use, and Correct At A Glance
You should find this implementation feels easy to call and modify and review. Please consider sharing your experience in the discussion tab.
FIXME
Fast
You should agree this implementation feels like it could run fast in 2007 SL before Mono. Please consider contributing measures of how much faster/ smaller this code is to the discussion tab.
FIXME
Small
You should agree that reworking the correct-at-a-glance implementation to make the code run faster feels like making the LSL compiler produce more byte code. Please consider contributing smaller code here.
Demo
Print the most astonishing test cases and then also the permission masks of a script.
Code:
FIXME
Sample Results:
FIXME
Specification By Consensus
We programmers divide into schools by our passionately held personal aesthetics, just like other poets. Not everyone here agrees exactly on the relative measures and importance of such fuzzy source code qualities as:
- easy to use
- correct at a glance
- small
- fast
The implementations we present here work exactly like the hex function of the Python scripting language, doc'ed deep within http://docs.python.org/lib/built-in-funcs.html after such disputes over its detailed specification as http://www.python.org/dev/peps/pep-0237/
Specifically, these implementations:
- return lower case a b c d e f rather than upper case A B C D E F,
- return a signed 31-bit result if negative, rather than an unsigned 32-bit result, and
- omit the leading quads of zeroed bits, except returns "0x0" rather than "0x" when the result is zero.
In this way, these implementations reproduce how hex integer literals often appear in LSL script, conforming to such traditional AT&T C conventions as:
- Return a meaningless "0" before the "x", as LSL and C compilers require.
- Return the "x" on the left as in LSL and C, not the "h" on the right as in Assembly code.
- Return the nybbles listed from most to least significant as in English, not listed from least to most significant as in Arabic.
As you read this page, you have to wade thru more than one implementation only because not all our community yet agrees that the only code you wish to see is the code from my school.