/
BitWiseExtension.xojo_code
90 lines (82 loc) · 1.92 KB
/
BitWiseExtension.xojo_code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#tag Module
Protected Module BitWiseExtension
#tag Method, Flags = &h0
Function Changebit(i as UInteger, bit as integer, value as boolean) As uinteger
dim result as uinteger
if value then
result = setbit(i, bit)
else
result = clearbit(i, bit)
end if
return result
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function ClearBit(i as UInteger, bit as integer) As uinteger
if HasBit (i, bit) then
dim compare as uinteger = 2 ^ bit
i = i - compare
return i
end if
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function HasBit(i as UInteger, bit as integer) As Boolean
dim compare as uinteger = 2 ^ bit
return (i and compare) = compare
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function SetBit(i as uinteger, bit as integer) As uint32
dim compare as uinteger = 2 ^ bit
return i or compare
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function SetBitInt(i as integer, bit as integer) As integer
dim compare as integer = 2 ^ bit
return i or compare
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function ShiftLeft(Extends I as Uinteger, bits as integer) As UInteger
Return I *(2^bits)
End Function
#tag EndMethod
#tag ViewBehavior
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag EndViewBehavior
End Module
#tag EndModule