Difference between revisions of "Int2Hex"
Jump to navigation
Jump to search
m |
m (<lsl> tag to <source>) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 13: | Line 13: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrRtn; | string vStrRtn; | ||
do{ | do{ | ||
Line 24: | Line 24: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Labeled Terse</h3> | <h3>Labeled Terse</h3> | ||
Line 31: | Line 31: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrRtn; | string vStrRtn; | ||
do{ | do{ | ||
Line 42: | Line 42: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Full</h3> | <h3>Full</h3> | ||
Line 49: | Line 49: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrRtn; | string vStrRtn; | ||
integer vIntCnt = 8; | integer vIntCnt = 8; | ||
Line 62: | Line 62: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Labeled Full</h3> | <h3>Labeled Full</h3> | ||
Line 69: | Line 69: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrRtn; | string vStrRtn; | ||
integer vIntCnt = 8; | integer vIntCnt = 8; | ||
Line 82: | Line 82: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Portable Terse</h3> | <h3>Portable Terse</h3> | ||
Line 89: | Line 89: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrSgn; | string vStrSgn; | ||
if (vIntBit >> 31){ | if (vIntBit >> 31){ | ||
Line 105: | Line 105: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Portable Labeled Terse</h3> | <h3>Portable Labeled Terse</h3> | ||
Line 112: | Line 112: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrSgn; | string vStrSgn; | ||
if (vIntBit >> 31){ | if (vIntBit >> 31){ | ||
Line 128: | Line 128: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Portable Full</h3> | <h3>Portable Full</h3> | ||
Line 135: | Line 135: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrSgn; | string vStrSgn; | ||
//-- Fixed Width alternates of the above line (208 Bytes LSO - 512 Bytes Mono) | //-- Fixed Width alternates of the above line (208 Bytes LSO - 512 Bytes Mono) | ||
Line 156: | Line 156: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
<h3>Portable Labeled Full</h3> | <h3>Portable Labeled Full</h3> | ||
Line 163: | Line 163: | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
<!-- Please replace with similarly licensed code only --> | <!-- Please replace with similarly licensed code only --> | ||
< | <source lang="lsl2">string uInteger2Hexadecimal( integer vIntBit ){ | ||
string vStrSgn; | string vStrSgn; | ||
//-- Fixed Width alternates of the above line (214 Bytes LSO - 512 Bytes Mono) | //-- Fixed Width alternates of the above line (214 Bytes LSO - 512 Bytes Mono) | ||
Line 184: | Line 184: | ||
/*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2010 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source> | ||
}} | }} | ||
Line 197: | Line 197: | ||
{{void-box | {{void-box | ||
|title= | |title=See Also | ||
|content= | |content= | ||
* [[User:Strife_Onizuka/int2hex]] - Another Integer->Hex function but without using a loop. | * [[User:Strife_Onizuka/int2hex]] - Another Integer->Hex function but without using a loop. | ||
<!-- what, no reciprocal linking Zai? =P --> | |||
{{Issues/SVC-6660}} | |||
{{IssueTable}} | |||
}} | }} | ||
[[Category:LSL_User-Defined_Functions]] | [[Category:LSL_User-Defined_Functions]] |
Latest revision as of 14:16, 22 January 2015
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 hexadecimal
- vIntBit: source integer to convert
Terse
(Leading zeros removed)
- LSO: 134 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
Labeled Terse
("0x" prefix, Leading zeros removed)
- LSO: 140 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
Full
(Leading zeros included)
- LSO: 153 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
Labeled Full
("0x" prefix, Leading zeros included)
- LSO: 159 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
Portable Terse
(Sign prefix, Leading zeros removed)
- LSO: 188 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
Portable Labeled Terse
(Sign prefix, "0x" prefix, Leading zeros removed)
- LSO: 194 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
Portable Full
(Sign prefix, Leading zeros included)
- LSO: 207 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
Portable Labeled Full
(Sign prefix, "0x" prefix, Leading zeros included)
- LSO: 213 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
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
See Also
- User:Strife_Onizuka/int2hex - Another Integer->Hex function but without using a loop.
SVC-6660 | A | llIntegerToHex() - function for integer/hex conversion |