Hi
I have a need for using bitwise operators (And, Or, XOR) on values in excess of 128bits so I wondered if there were any tools in Purebasic for this type of thing. I am assuming if not that I could just do 64bits at a time and store the result in a memory buffer.
Thanks,
Simon
Bitwise Operations on Memory larger than 64bits
Bitwise Operations on Memory larger than 64bits
Simon White
dCipher Computing
dCipher Computing
Re: Bitwise Operations on Memory larger than 64bits
this may help
viewtopic.php?f=12&t=57409
viewtopic.php?f=12&t=57409
Windows 11, Manjaro, Raspberry Pi OS
Re: Bitwise Operations on Memory larger than 64bits
You can use structures ...
Code: Select all
;-TOP
Structure ArrayOfAny
a.a[0]
b.b[0]
w.w[0]
u.u[0]
l.l[0]
q.q[0]
EndStructure
Structure Var128
StructureUnion
q.q[2]
splice.ArrayOfAny
EndStructureUnion
EndStructure
Procedure And128(*Result.Var128, *Value1.Var128, *Value2.Var128)
*Result\q[0] = *Value1\q[0] & *Value2\q[0]
*Result\q[1] = *Value1\q[1] & *Value2\q[1]
EndProcedure
Procedure Or128(*Result.Var128, *Value1.Var128, *Value2.Var128)
*Result\q[0] = *Value1\q[0] | *Value2\q[0]
*Result\q[1] = *Value1\q[1] | *Value2\q[1]
EndProcedure
Procedure XOr128(*Result.Var128, *Value1.Var128, *Value2.Var128)
*Result\q[0] = *Value1\q[0] ! *Value2\q[0]
*Result\q[1] = *Value1\q[1] ! *Value2\q[1]
EndProcedure
Procedure.s Hex128(*Value.Var128)
Protected r1.s
r1 = RSet(Hex(*Value\q[1], #PB_Quad), 16, "0")
r1 + RSet(Hex(*Value\q[0], #PB_Quad), 16, "0")
ProcedureReturn r1
EndProcedure
Define v1.Var128
Define v2.Var128
Define r1.Var128
v1\q[0] = $FF00000001020304 ; Low Quad
v1\q[1] = $00FFFFFF10203040 ; High Quad
v2\q[0] = $F0F0F0F0F0F0F0F0
v2\q[1] = $F0F0F0F0F0F0F0F0
And128(r1, v1, v2)
Debug Hex128(v1)
Debug Hex128(v2)
Debug "And"
Debug Hex128(r1)
Debug "----"
Debug "Splice v1"
For i = 0 To 15
Debug RSet(Hex(v1\splice\a[i]), 2, "0")
Next
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Bitwise Operations on Memory larger than 64bits
Thank-you that is quite useful.
Simon
Simon
Simon White
dCipher Computing
dCipher Computing