1
+ /%
2
+ Converts @"num" into a 64 character binary number.
3
+
4
+ `3354674` -> `00000000000000000000000000000000000000000001100110011000000110010`
5
+ %/
1
6
func str toBin(int num) {
2
7
str out = "";
3
8
for (int i : 0..65) {
@@ -13,6 +18,11 @@ func str toBin(int num) {
13
18
ret out;
14
19
}
15
20
21
+ /%
22
+ Converts the bits of @"a" into a decimal number.
23
+
24
+ No type conversion is done. Use casting if you intend on the numerical values matching.
25
+ %/
16
26
func dec rawCastIntToDec(int a) {
17
27
dec o = 0.0;
18
28
assembly {
@@ -23,6 +33,11 @@ func dec rawCastIntToDec(int a) {
23
33
ret o;
24
34
}
25
35
36
+ /%
37
+ Converts the bits of @"a" into a integer.
38
+
39
+ No type conversion is done. Use casting if you intend on the numerical values matching.
40
+ %/
26
41
func int rawCastDecToInt(dec a) {
27
42
int o = 0;
28
43
assembly {
@@ -33,10 +48,16 @@ func int rawCastDecToInt(dec a) {
33
48
ret o;
34
49
}
35
50
51
+ /%
52
+ Returns the @"n"th bit of @"a".
53
+ %/
36
54
func int nthBit(int n, int a) {
37
55
ret and(shr(a, n), 1);
38
56
}
39
57
58
+ /%
59
+ Returns the bitwise and of @"a" and @"b".
60
+ %/
40
61
func int and(int a, int b) {
41
62
int o = 0;
42
63
assembly {
@@ -49,6 +70,9 @@ func int and(int a, int b) {
49
70
ret o;
50
71
}
51
72
73
+ /%
74
+ Returns the bitwise or of @"a" and @"b".
75
+ %/
52
76
func int or(int a, int b) {
53
77
int o = 0;
54
78
assembly {
@@ -61,6 +85,9 @@ func int or(int a, int b) {
61
85
ret o;
62
86
}
63
87
88
+ /%
89
+ Returns the bitwise xor of @"a" and @"b".
90
+ %/
64
91
func int xor(int a, int b) {
65
92
int o = 0;
66
93
assembly {
@@ -73,6 +100,9 @@ func int xor(int a, int b) {
73
100
ret o;
74
101
}
75
102
103
+ /%
104
+ Returns the bitwise not of @"a".
105
+ %/
76
106
func int not(int a) {
77
107
int o = 0;
78
108
assembly {
@@ -84,6 +114,10 @@ func int not(int a) {
84
114
ret o;
85
115
}
86
116
117
+ /%
118
+ Returns @"a" bit-shifted to the left by @"b".
119
+ @"b" gets down casted into a 8-bit number (0-255). Upper bits are ignored.
120
+ %/
87
121
func int shl(int a, int b) {
88
122
int o = 0;
89
123
assembly {
@@ -96,6 +130,10 @@ func int shl(int a, int b) {
96
130
ret o;
97
131
}
98
132
133
+ /%
134
+ Returns @"a" bit-shifted to the right by @"b".
135
+ @"b" gets down casted into a 8-bit number (0-255). Upper bits are ignored.
136
+ %/
99
137
func int shr(int a, int b) {
100
138
int o = 0;
101
139
assembly {
0 commit comments