[Papyrus] No bitwise Ops?

Post » Tue Jun 19, 2012 6:26 pm

There doesn't seem to be any bitwise oerators.
Please somebody tell me I'm being blind.
User avatar
Tamara Dost
 
Posts: 3445
Joined: Mon Mar 12, 2007 12:20 pm

Post » Tue Jun 19, 2012 2:51 pm

Nope, the wiki's http://www.creationkit.com/Operator_Reference doesn't list any bitwise operators.

Cipscis
User avatar
Anna Watts
 
Posts: 3476
Joined: Sat Jun 17, 2006 8:31 pm

Post » Tue Jun 19, 2012 8:42 am

Thanks Cipscis. I looked there and in Math.psc. So it's just not my bad eyes :(

I'm Using a hack for now
Spoiler

int Function bitwiseAnd8 (int i1, int i2) Global;quick hackjob - I miss SKSE already;would probably be better in a loopReturn \((i1	   - i1 % 128) / 128 * (i2	   - i2 % 128) / 128) * 128 + \((i1 % 128 - i1 %  64) /  64 * (i2 % 128 - i2 %  64) /  64) *  64 + \((i1 %  64 - i1 %  32) /  32 * (i2 %  64 - i2 %  32) /  32) *  32 + \((i1 %  32 - i1 %  16) /  16 * (i2 %  32 - i2 %  16) /  16) *  16 + \((i1 %  16 - i1 %   8) /   8 * (i2 %  16 - i2 %   8) /   8) *   8 + \((i1 %   8 - i1 %   4) /   4 * (i2 %   8 - i2 %   4) /   4) *   4 + \((i1 %   4 - i1 %   2) /   2 * (i2 %   4 - i2 %   2) /   2) *   2 + \(i1 %   2)				  * (i2 % 2)EndFunction

Thankfully I won't be needing bitwiseOR just yet.

Edit: I'd forgotten the return type.
User avatar
Tom
 
Posts: 3463
Joined: Sun Aug 05, 2007 7:39 pm

Post » Tue Jun 19, 2012 7:42 pm

Just curious what do you need then for?
User avatar
sara OMAR
 
Posts: 3451
Joined: Wed Jul 05, 2006 11:18 pm

Post » Tue Jun 19, 2012 9:38 pm

I'm passing an optionFlags integer to a general maintenance quest script.
The idea being that I can add some more options for project 2, without breaking an already working project 1.

Well that's the idea, whether it pans out or not is another matter.
User avatar
Jennifer Rose
 
Posts: 3432
Joined: Wed Jan 17, 2007 2:54 pm

Post » Tue Jun 19, 2012 8:25 am

Here's a better bitwise solution for mods needing these before we get them SKSE, or if your mods doesn't require SKSE or other plugins.

Let me know if you spot bugs, or have improvements. Cheers.

Spoiler

Int Function bitwiseOp(Int i1, Int i2, Int iBits = 31, Int iOp = 1, Bool bWarn = False) Global{31 bitwise operations.  Returns a negative number on errorsSet iBits lower to limit the bitmask to the lower bits for efficiency - Def = 31bitsSet bOp for the bitwise operation. 0 = NOT, 1 = AND(default), 2 = OR, 3 = XORSet bWarn to True if you are too lazy to check the error return value, and want a notification}int iRes = 0 ; Accumulated resultint iDiv;iBits Sanity checksIf iBits < 1  Return 0EndIfIf iBits > 31  iRes = -3 ; iBits too highElseIf i1 < 0  iRes = -1 ; 1st param -veElseIf iOp && (i2 < 0)  iRes = -2 ; 2nd param -veEndIfIf iRes != 0  If bWarn   Debug.Notification("PARAMETER ERROR in function bitwiseOp. Code = " + iRes )  EndIf  Return iResEndIf; Throw away the upper bitsIf iBits != 31  int i = Math.Pow(2, iBits) As Int  i1 %= i  i2 %= iEndIf; Init divisor to loop from MSBsiDiv = Math.Pow(2, (iBits - 1)) As IntIf iOp == 1 ; AND  If !i1 || !i2   Return 0  EndIf  While(iBits)   If ((i1 / iDiv) As Int) && ((i2 / iDiv) As Int)	iRes += iDiv   EndIf   i1 %= iDiv   i2 %= iDiv   iDiv /= 2   iBits -= 1  EndWhileElseIf iOp == 2 ; OR  If !i1 && !i2   Return 0  EndIf  While(iBits)   If ((i1 / iDiv) As Int) || ((i2 / iDiv) As Int)	iRes += iDiv   EndIf   i1 %= iDiv   i2 %= iDiv   iDiv /= 2   iBits -= 1  EndWhileElseIf iOp == 3 ; XOR  While(iBits)   int a = i1 / iDiv   int b = i2 / iDiv   If (( a && !b ) || ( !a && B))	iRes += iDiv   EndIf   i1 %= iDiv   i2 %= iDiv   iDiv /= 2   iBits -= 1  EndWhileElseIf iOp == 0 ; NOT  While(iBits)   If !((i1 / iDiv) As Int)	iRes += iDiv   EndIf   i1 %= iDiv   iDiv /= 2   iBits -= 1  EndWhileElseIf bWarn  Debug.Notification("PARAMETER ERROR in function bitwiseOp. Code = -4 (unknown iOp)")  Return -4EndIfReturn iResEndFunction


Edit: cast to Int in conditionals where it may matter
User avatar
Milagros Osorio
 
Posts: 3426
Joined: Fri Aug 25, 2006 4:33 pm

Post » Tue Jun 19, 2012 11:07 pm

I see sounds like a good idea.
User avatar
Jade
 
Posts: 3520
Joined: Mon Jul 10, 2006 6:42 am

Post » Tue Jun 19, 2012 11:34 pm

It's unfortunate that we can only set arrays element by element, as a bool array property could have been great for this.

Cipscis
User avatar
naome duncan
 
Posts: 3459
Joined: Tue Feb 06, 2007 12:36 am


Return to V - Skyrim