Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

integer and base64 conversion functions

Phoenix Linden
SL's Angel of Death
Join date: 3 Dec 2002
Posts: 168
03-20-2006 16:50
While fixing up our base64 usage in the lsl engine, I found that the functions that llIntegerToBase64 and llBase64ToInteger only process 24 bits of data - which means that all kinds of data including the sign are potentially lost in the conversion, so you might not get back the same thing you put in. For example:

integer foo = 269336926;
integer bar = llBase64ToInteger(llIntegerToBase64(foo));
if(foo != bar)
{
llOwnerSay("Large integer test Failed.";);
}
foo = -1;
bar = llBase64ToInteger(llIntegerToBase64(foo));
if(foo != bar)
{
llOwnerSay("Negative integer test Failed.";);
}


Will fail in both cases. I would like to correct this so that this works for all 32 bit integers. This will require a slightly different representation for integers encoded as base64 sent out on the wire. Specifically, I will encode the 4 bytes of the integer in network byte order as base64 and vice-versa.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-20-2006 17:09
Are you saying you want to reverse the byte order? (EDIT: i see what you mean about them being screwed up)

It's faster for me to run my own home brewed function then use llBase64ToInteger, could you ease up on the delay?

Just had an idea...
Could you add...

integer llCharacter2Integer(string chr, integer index)
would return the ascii (well Unicode really) value for the indexed character (a negitive index would count from the end).

string llInteger2Character(integer unicode)
would return a string with the unicode character of unicode.

They would make working with strings alot easier when dealing with unicode characters (no more mucking around with custom built UTF-8 (en|de)coders).
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey