-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
47 lines (42 loc) · 1.13 KB
/
main.ts
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
/* *************** */
/*We use block="string" to override the block drop-down text */
enum operator{
//% block="&"
and,
//% block="|"
or,
//% block="^"
xor,
//% block="<<"
leftShift,
//% block=">>"
rightShift,
//% block=">>>"
zeroFillRightShift
}
//% weight=20 color=#05a167 icon="\uf101" block="Bitwise logic"
namespace BitwiseLogic {
//% blockId="bitwise_2arg" block="%a %fn %b"
//% weight=98 blockGap=8
export function bitwise2arg(a: number, fn: operator, b:number) {
switch (fn){
case operator.and: return(a & b)
break
case operator.or: return(a | b)
break
case operator.xor: return(a ^ b)
break
case operator.leftShift: return(a << b)
break
case operator.rightShift: return(a >> b)
break
case operator.zeroFillRightShift: return(a >>> b)
break
}
}
//% blockId="bitwise_not" block="~ %a"
//% weight=94 blockGap=8
export function bitwiseNot(a: number){
return(~a)
}
}