-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmagicTester.bb_bak2
More file actions
171 lines (113 loc) · 3.15 KB
/
bitmagicTester.bb_bak2
File metadata and controls
171 lines (113 loc) · 3.15 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
;; bitmagic.DLL Tester
;; Notes :: Test the following :::
;;; reversebyteQ(int v)
Graphics 900,600,32,2
Global T[5]
v = 7
For z=1 To 36
Print" "+Bin$(v) + " : "+Hex$(v)
v = BinToGray(v)
Next
Print
we()
For z=000 To 032
Print" z="+z+" : "+Bin$(z)+" : "+ leadingzeroes(z)+" : "+trailingzeroes(z)
Next
Print
we()
Delay(10)
x = 0
y = $FFFFFFFF
Print
T[0] = MilliSecs()
For loop = 1 To 40000000
interleave2Shorts(x,y)
Next
T[1] = MilliSecs()
T[2] = MilliSecs()
For loop = 1 To 40000000
interleave2ShortsM(x,y)
Next
T[3] = MilliSecs()
T[4] = MilliSecs()
For loop = 1 To 40000000
interleave2Shorts_obvious(x,y)
Next
T[5] = MilliSecs()
Print
Print" interleave2Shorts(x,y) Time = "+(T[1]-T[0])
Print" interleave2ShortsM(x,y) Time = "+(T[3]-T[2])
Print" interleave2Shorts_obvious(x,y) Time = "+(T[5]-T[4])
Print
;;WaitKey():End
For y = $FFFFFFFF To $FFFFFFFF+1
For x =0 To 3
r = interleave2Shorts(x,y) : rr = interleave2ShortsM(x,y) :: rrr = interleave2Shorts_obvious(x,y)
Print" ("+Right$(Bin$(x),16)+","+Right$(Bin$(y),16)+") : "+Right$(Bin$(r),32)+" : "+Right$(Bin$(rrr),32) +" : " ;+Right$(Bin$(rrr),32)
Next
Next
Print
WaitKey():End
For z=0 To 32
Print" z="+z+" : "+bitnot8(z)+" : "+bitcount16A(z)+" : "+Right$(Bin$(bitnot8(z)),16)
Next
Print
WaitKey():End
s$ = " { " : ss$ = ""
fp = WriteFile("DataFile.txt")
;For z=256 To 226 Step -1
; x = reversebyteQ(z)
; Print" z="+z+" : "+Right$(Bin$(z),8)+" : "+Right$(Bin$(x),8)
;Next
For z=0 To 255
;s = s + (1-oddparitybyteF(z))+","
If Len(s)>100
WriteLine(fp,s)
s = ""
End If
;Print" z="+z+" : "+Right$(Bin$(oddparitybyteF(z)),8)+" : "+Right$(Bin$(oddparitybyteF(z)),8)
Next
WriteLine(fp,s+" }; ")
CloseFile fp
Print
Print" End of Program. "
WaitKey():End
;; gray code generator
;; source: http://en.wikipedia.org/wiki/Gray_code
Function Gray(n)
Return (n Shr 1) Xor n
End Function
Function GrayToBin_B(n)
Local mask
mask=(n Shr 1)
While(mask)
n = n Xor mask
mask = mask Shr 1
Wend
Return n
End Function
;; returns a slimmer hex$ without leading zeroes.
;;
Function SlimHex$(v)
h$ = Hex$(v)
If v< 16 Then Return Mid$(h,8,1)
If v< 256 Then Return Mid$(h,7,2)
If v< 4096 Then Return Mid$(h,6,3)
If v< 65536 Then Return Mid$(h,5,4)
If v< 1048576 Then Return Mid$(h,4,5)
If v< 16777216 Then Return Mid$(h,3,6)
If v<268435456 Then Return Mid$(h,2,7)
Return h
End Function
Function bitcount(n) ;; A bitcount computation ...
If n <0 Then Return 0
Local c= 0 ; count
While(n)
c = c + 1
n = n And (n-1) ; sets the least significant bit to zero
Wend
Return c
End Function
Function we()
WaitKey():End
End Function