Update: so you can do math operations on ref instead of long and it almost seems to be behaving as a 32bit unsigned integer... except the bit operations seem to be choking still... see post below.
Does anyone have any experience generating 32bit unsigned longs for use as reference IDs in an Oblivion script?
I'm currently getting crapped on by the script engine. For More-Armor-Slots, I am doing bit arithmetic to generate a 32bit unsigned number that I then convert to a ReferenceID. Unfortunately, OBSE/Oblivion Script does not natively support unsigned long, so I'm try to manipulate a signed long so it turns into the bit-equivalent of the 32bit unsigned long value I want so I can convert into a RefID. Example:
If I try to generate 7F00:13E1 (which uses 31 bits and leaves the 32nd bit = 0) OBSE handles the number perfectly and I can pass it to pluggy to create a Reference ID.
But:
If I try to generate FF00:13E1 (the 32nd bit is now = 1) OBSE will now do stupid things like trying to print out a 64bit hex string when I specify formating for 32bit hex string and it is always the following string no matter what the actual result of my math should be: FFFFFFFF80000000.
I'm about to look through the OBSE source code, but wanted to ask here just in case this is something that's been solved years ago.

Alright, I now have a partial
Alright, I now have a partial solution to my problems: instead of declaring variables of type long, I can declare variables of type ref. When using type ref, I can do a left-shift for 16 bits and get a correct result.
However, LogicalOr operations on ref values that have the 32nd bit set seem to give incorrect results. example: script result is 800013E1 when the expected result is FF0013E1.
And adding two refs together appears to be going through a int->float conversion, because the result is rounded off: example -> script result is FF001400 when the expected result is FF0013E1.
Update: If I do two bit operations like this, then it seems to work but then more crap happens -- it appears to be stuck as a number and will not work as a reference unless I convert it into a reference with Pluggy's LongToRef.
BUT now, when I use Pluggy's LongToRef on a number with the 32nd bit set, the script engine breaks again. GAH!!!