Difference between revisions of "Int2Hex"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 4: Line 4:
|title=<div style="display:none"><h2>Summary</h2></div>[[: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



Revision as of 18:21, 1 June 2010

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

<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

Links