I need the command bitwisexor. Somebody an idea to do that?
Jens
Here is a post from Kem Tekinay I picked up in the beta forum about the absence of bitwise in iOS. It may help :
You can still use AND, OR, and XOR as you could with the old framework.
Shift left/right can be emulated with value * 2^bits or value \ 2^bits.
Ones complement can be achieved with this code:
dim ones as UInt64 = &hFFFFFFFFFFFFFFFF
value = value Xor ones
I found it. It is just simple:
dim a as UInt32 = 3
dim b as UInt32 = 7
dim result as Uint32 = (a xor b)
I’m confused…
I have the following
' value As UInt64, shift As Integer, bits As Integer
Dim result as UInt64 = Bitwise.ShiftLeft(value, shift, bits)
How do I translate this in new framework with
value * 2^bits
I’m missing the shift parameter, no ?
No, in your example, it’s missing the “bits”.
If I rewrite the params to be a bit clearer:
result = Bitwise.ShiftLeft( value, placesToShift, numOfBitsToShift )
that would translate to:
result = value * 2^placesToShift
You control the number of bits to shift by declaring your value and result accordingly, or applying a mask after the shift.
Now it’s clear !
Thanks a lot Kem.
What would be nice to know is whether
result = Bitwise.ShiftLeft( value, placesToShift, numOfBitsToShift )
translates to a shift instruction in the processor, if that is the case substituting
result = value * 2^placesToShift
even though it works will result in a speed penalty for math intensive code. I still think that there should be a shift operator added to Xojo to go along side and, or, xor.
In prior testing I found that plain old XOR is way faster than Bitwise.XOR, so I suspect you are correct : if we had a dedicated << or >> operator there would be a speed improvement.
That’s because Bitwise.Xor is a method call with all its associated overhead whereas Xor is an operator.
To maximize the speed of math-based shift-left/right, create an array with all the values of 2^n, then lookup from the array.
static powersOf2() as UInt64
if powersOf2.Ubound = -1 then
dim two as UInt64 = 2
dim zero as UInt64 = 0
dim sixtyThree as UInt64 = 63
for i as UInt64 = zero to sixtyThree
powersOf2.Append two^i
next
end if
dim shiftL as UInt64 = value * powersOf2( places )
dim shiftR as UInt64 = value \\ powersOf2( places )
(I haven’t actually tried this in an iOS project so I can’t tell you if there is some framework-based reason it won’t work.)