Int2Hex
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials | User-Defined Functions | Void's User Page |
User-Defined Function: string uInteger2Hexadecimal( integer vIntBit );
Returns a string that is vIntBit converted to headecimal
- vIntBit: source integer to convert
Terse
(Leading zeros removed)
- LSO: 134 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrRtn; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; }while (vIntBit = vIntBit >> 4 & 0x0FFFFFFF); return vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>
Labeled Terse
("0x" prefix, Leading zeros removed)
- LSO: 140 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrRtn; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; }while (vIntBit = vIntBit >> 4 & 0x0FFFFFFF); return "0x" + vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>
Full
(Leading zeros included)
- LSO: 153 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrRtn; integer vIntCnt = 8; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; vIntBit = vIntBit >> 4; }while (vIntCnt = ~-vIntCnt); return vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>
Labeled Full
("0x" prefix, Leading zeros included)
- LSO: 159 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrRtn; integer vIntCnt = 8; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; vIntBit = vIntBit >> 4; }while (vIntCnt = ~-vIntCnt); return "0x" + vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>
Portable Terse
(Sign prefix, Leading zeros removed)
- LSO: 188 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrSgn; if (vIntBit >> 31){ vStrSgn = "-"; vIntBit = -vIntBit; } string vStrRtn; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; }while( vIntBit = vIntBit >> 4 & 0x0FFFFFFF ); return vStrSgn + vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>
Portable Labeled Terse
(Sign prefix, "0x" prefix, Leading zeros removed)
- LSO: 194 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrSgn; if (vIntBit >> 31){ vStrSgn = "-"; vIntBit = -vIntBit; } string vStrRtn; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; }while( vIntBit = vIntBit >> 4 & 0x0FFFFFFF ); return vStrSgn + "0x" + vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>
Portable Full
(Sign prefix, Leading zeros included)
- LSO: 207 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrSgn; //-- Fixed Width alternates of the above line (208 Bytes LSO - 512 Bytes Mono) //-- string vStrSgn = " "; //-- Format: "-80000000" to " 7FFFFFFF" //-- string vStrSgn = "+"; //-- Format: "-80000000" to "+7FFFFFFF" if (vIntBit >> 31){ vStrSgn = "-"; vIntBit = -vIntBit; } integer vIntCnt = 8; string vStrRtn; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; vIntBit = vIntBit >> 4; }while( vIntCnt = ~-vIntCnt ); return vStrSgn + vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>
Portable Labeled Full
(Sign prefix, "0x" prefix, Leading zeros included)
- LSO: 213 bytes
- MONO: 512 bytes
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
string vStrSgn; //-- Fixed Width alternates of the above line (214 Bytes LSO - 512 Bytes Mono) //-- string vStrSgn = " "; //-- Format: "-0x80000000" to " 0x7FFFFFFF" //-- string vStrSgn = "+"; //-- Format: "-0x80000000" to "+0x7FFFFFFF" if (vIntBit >> 31){ vStrSgn = "-"; vIntBit = -vIntBit; } integer vIntCnt = 8; string vStrRtn; do{ vStrRtn = llGetSubString( "0123456789ABCDEF", vIntBit & 0x0000000F, vIntBit & 0x0000000F ) + vStrRtn; vIntBit = vIntBit >> 4; }while( vIntCnt = ~-vIntCnt ); return vStrSgn + "0x" + vStrRtn;
} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*//-- --//*/</lsl>Notes
- All Labeled formats can be cast directly to integer within LSL
- Full formats are optimal for fixed width viewing, or packing into raw strings.
- Portable formats are designed for compatibility with outside systems that may use different bit lengths
- Suggest using the smallest compiled version that fits your needs