User talk:Becky Pippen/Numeric Storage
< User talk:Becky Pippen
Jump to navigation
Jump to search
Revision as of 20:50, 1 January 2010 by Strife Onizuka (talk | contribs) (Created page with 'I like this code and it shows you have put a decent amount of thought into it. I too take pleasure in writing algorithms and would like to give you my critique of the code. Howev...')
I like this code and it shows you have put a decent amount of thought into it. I too take pleasure in writing algorithms and would like to give you my critique of the code. However before I start I want to impress upon you that the logic of your implementation is not only sound it is pretty efficient.
Your approach in decodeCharTo15Bits surprised me (in a good way), I had to stop and really think about why I would have done it another way. As it stands you are using 3 string additions, and 4 function calls that work with strings. I'd rewrite it as: <lsl>integer decodeCharTo15Bits(string ch) {
integer val = llBase64ToInteger(llStringToBase64(ch));
return ((val & 0x1f000000) >> 12) + ((val & 0x003f0000) >> 10) + ((val & 0x00003f00) >> 8) - 0x1000;
}</lsl>
Similarly I would rewrite encode15BitsToChar', which eliminates the need for hexChar2.
<lsl>string encode15BitsToChar(integer num) {
// Check the incoming range
if (num < 0 || num >= 0x8000) { // illegal input -- do whatever is appropriate return "�"; }
// Bias the incoming numeric value by 0x1000 to avoid illegal Unicode codes:
num += 0x1000; // construct UTF-8 layout: num = 0xE0808000 | (num << 12) | ((num << 10) & 0x3f0000) | ((num << 8) & 0x3f00);
// Convert the UTF-8 into a 16-bit Unicode character:
return llGetSubString(llBase64ToString(llIntegerToBase64(num)), 0, 0);
}</lsl>