Difference between revisions of "LlIntegerToBase64"
Jump to navigation
Jump to search
If you are looking for full Unicode translation, not just ASCII7 see: Combined_Library
m (<lsl> tag to <source>) |
Frionil Fang (talk | contribs) (example on how to make use of fewer than 6 Base64 chars) |
||
Line 8: | Line 8: | ||
|caveats | |caveats | ||
|constants | |constants | ||
|examples=< | |examples=<syntaxhighlight lang="lsl2">string ASCII7ToString(integer letter) | ||
{ | { | ||
if(letter >= 0x80 || letter < 0) return "";//Not valid ascii7 character | if(letter >= 0x80 || letter < 0) return "";//Not valid ascii7 character | ||
return llBase64ToString(llIntegerToBase64(letter << 24)); | return llBase64ToString(llIntegerToBase64(letter << 24)); | ||
}</ | }</syntaxhighlight> | ||
<syntaxhighlight lang="lsl2">// Packs a 24-bit unsigned integer value (0-16777215) to only 4 Base64 characters. | |||
string Int24ToBase64(integer value) | |||
{ | |||
return llGetSubString(llIntegerToBase64(value<<8), 0, 3); | |||
} | |||
// unpacks a 4-character Base64 value to a 24-bit unsigned integer | |||
integer Base64ToInt24(string value) | |||
{ | |||
return (llBase64ToInteger(value)>>8)&0xffffff; // Masking required to remove sign extension from bit-shifting | |||
} | |||
</syntaxhighlight> | |||
If you are looking for full Unicode translation, not just ASCII7 see: [[Combined_Library#Unicode_Integer_to_UTF8|Combined_Library]] | If you are looking for full Unicode translation, not just ASCII7 see: [[Combined_Library#Unicode_Integer_to_UTF8|Combined_Library]] | ||
|helpers | |helpers | ||
Line 22: | Line 33: | ||
|also_tests | |also_tests | ||
|also_articles | |also_articles | ||
|notes=Only the first 6 of the 8 characters returned are needed to decoded it back into an integer. | |notes=*Only the first 6 of the 8 characters returned are needed to decoded it back into an integer. The padding "==" can be safely removed for storage. | ||
|cat1=Base64 | |cat1=Base64 | ||
|cat2=Encoding | |cat2=Encoding |
Revision as of 10:43, 11 October 2023
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: string llIntegerToBase64( integer number );280 | Function ID |
0.0 | Forced Delay |
10.0 | Energy |
Returns a string that is a Base64 big endian encode of number
• integer | number |
Caveats
Examples
string ASCII7ToString(integer letter)
{
if(letter >= 0x80 || letter < 0) return "";//Not valid ascii7 character
return llBase64ToString(llIntegerToBase64(letter << 24));
}
// Packs a 24-bit unsigned integer value (0-16777215) to only 4 Base64 characters.
string Int24ToBase64(integer value)
{
return llGetSubString(llIntegerToBase64(value<<8), 0, 3);
}
// unpacks a 4-character Base64 value to a 24-bit unsigned integer
integer Base64ToInt24(string value)
{
return (llBase64ToInteger(value)>>8)&0xffffff; // Masking required to remove sign extension from bit-shifting
}
Notes
- Only the first 6 of the 8 characters returned are needed to decoded it back into an integer. The padding "==" can be safely removed for storage.
See Also
Functions
• | llBase64ToInteger | |||
• | llBase64ToString | |||
• | llStringToBase64 |