Difference between revisions of "Int2Hex"

From Second Life Wiki
Jump to navigation Jump to search
(new page)
 
m (<lsl> tag to <source>)
 
(5 intermediate revisions by 4 users not shown)
Line 2: Line 2:
<div style="float:right;">__TOC__</div>
<div style="float:right;">__TOC__</div>
{{void-box
{{void-box
|title=<span style="display:none"><h2>Summary</h2></span>[[:Category:LSL_User-Defined_Functions|User-Defined Function]]: [[string]] uInteger2Hexadecimal( [[integer]] ''vIntBit'' );
|title=<div style="display:none"><h2>Summary</h2></div>[[:Category:LSL_User-Defined_Functions|User-Defined Function]]: [[string]] uInteger2Hexadecimal( [[integer]] ''vIntBit'' );
|content=
|content=
Returns a string that is ''vIntBit'' converted to headecimal
Returns a string that is ''vIntBit'' converted to hexadecimal
* ''vIntBit'': source integer to convert
* ''vIntBit'': source integer to convert


Line 13: Line 13:
* MONO: 512 bytes
* MONO: 512 bytes
<!-- Please replace with similarly licensed code only -->
<!-- Please replace with similarly licensed code only -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</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 -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</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 -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</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 -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</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 -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</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 -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</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 -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</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 -->
<lsl>string uInteger2Hexadecimal( integer vIntBit ){
<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 ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</source>
}}
}}


Line 196: Line 196:
}}
}}


{{void-box
|title=See Also
|content=
* [[User:Strife_Onizuka/int2hex]] - Another Integer-&gt;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

Summary

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

   llIntegerToHex() - function for integer/hex conversion