Difference between revisions of "LlBase64ToInteger"

From Second Life Wiki
Jump to navigation Jump to search
m (Parameter description)
(the return is always predictable: if there's fewer than 6 characters, any incomplete bytes of the integer become 0 (e.g. 5 chars->30 bits->only 3 complete bytes with low byte set to 0))
 
(3 intermediate revisions by 3 users not shown)
Line 5: Line 5:
|return_text=that is '''str''' {{LSLGC|Base64}} decoded as a big endian integer.
|return_text=that is '''str''' {{LSLGC|Base64}} decoded as a big endian integer.
|spec
|spec
|caveats=*If '''str''' contains fewer then 6 characters the return is unpredictable.
|caveats=*If {{LSLPT|str}} contains fewer than 6 characters, any incomplete least-significant bytes of the integer are set to 0.
**[[User:Strife Onizuka|BW]]: I think it ignores the null and reads 6 bytes regardless which would explain why the return is unpredictable.
**For example, the Base64 value <code>"qqqqqq=="</code> corresponds to the hexadecimal value <code>0xAAAAAAAA</code>. If the padding "=" characters and the last "q" are dropped, there are 5*6=30 bits remaining and those can form only 3 full bytes (24 bits). The result is <code>0xAAAAAA00</code>.
*Returns zero if '''str''' is longer then 8 characters.
**The Base64 value <code>"qqqq"</code> has 4*6=24 bits available, which is enough for the same 3 full bytes. The result is also <code>0xAAAAAA00</code>.
**Similarly, 3-character Base64 has 18 bits, enough for 2 bytes, and 2-character Base64 has 12 bits, enough for one byte.
**Finally, single-character Base64 has only 6 bits and thus no complete bytes, and the result is always zero.
*Returns zero if {{LSLPT|str}} is longer than 8 characters.
|constants
|constants
|examples=<lsl>
|examples=<source lang="lsl2">
integer value = llBase64ToInteger("3q0AAA==");
integer value = llBase64ToInteger("3q0AAA==");


// writes out -559087616
// writes out -559087616
llOwnerSay((string)value);
llOwnerSay((string)value);
</lsl>
</source>
|helpers
|helpers
|also_functions={{LSL DefineRow||{{LSLG|llIntegerToBase64}}|}}
|also_functions={{LSL DefineRow||{{LSLG|llIntegerToBase64}}|}}

Latest revision as of 09:30, 11 October 2023

Summary

Function: integer llBase64ToInteger( string str );
0.0 Forced Delay
10.0 Energy

Returns an integer that is str Base64 decoded as a big endian integer.

• string str Base64 string

Caveats

  • If str contains fewer than 6 characters, any incomplete least-significant bytes of the integer are set to 0.
    • For example, the Base64 value "qqqqqq==" corresponds to the hexadecimal value 0xAAAAAAAA. If the padding "=" characters and the last "q" are dropped, there are 5*6=30 bits remaining and those can form only 3 full bytes (24 bits). The result is 0xAAAAAA00.
    • The Base64 value "qqqq" has 4*6=24 bits available, which is enough for the same 3 full bytes. The result is also 0xAAAAAA00.
    • Similarly, 3-character Base64 has 18 bits, enough for 2 bytes, and 2-character Base64 has 12 bits, enough for one byte.
    • Finally, single-character Base64 has only 6 bits and thus no complete bytes, and the result is always zero.
  • Returns zero if str is longer than 8 characters.

Examples

integer value = llBase64ToInteger("3q0AAA==");

// writes out -559087616
llOwnerSay((string)value);

See Also

Functions

•  llIntegerToBase64

Articles

•  Base64

Deep Notes

Signature

function integer llBase64ToInteger( string str );