Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Bitwise-operations/R/bitwise-operations-1.r
Normal file
10
Task/Bitwise-operations/R/bitwise-operations-1.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Since R 3.0.0, the base package provides bitwise operators, see ?bitwAnd
|
||||
|
||||
a <- 35
|
||||
b <- 42
|
||||
bitwAnd(a, b)
|
||||
bitwOr(a, b)
|
||||
bitwXor(a, b)
|
||||
bitwNot(a)
|
||||
bitwShiftL(a, 2)
|
||||
bitwShiftR(a, 2)
|
||||
5
Task/Bitwise-operations/R/bitwise-operations-2.r
Normal file
5
Task/Bitwise-operations/R/bitwise-operations-2.r
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a <- as.hexmode(35)
|
||||
b <- as.hexmode(42)
|
||||
as.integer(a & b) # 34
|
||||
as.integer(a | b) # 43
|
||||
as.integer(xor(a, b)) # 9
|
||||
13
Task/Bitwise-operations/R/bitwise-operations-3.r
Normal file
13
Task/Bitwise-operations/R/bitwise-operations-3.r
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
intToLogicalBits <- function(intx) as.logical(intToBits(intx))
|
||||
logicalBitsToInt <- function(lb) as.integer(sum((2^(0:31))[lb]))
|
||||
"%AND%" <- function(x, y)
|
||||
{
|
||||
logicalBitsToInt(intToLogicalBits(x) & intToLogicalBits(y))
|
||||
}
|
||||
"%OR%" <- function(x, y)
|
||||
{
|
||||
logicalBitsToInt(intToLogicalBits(x) | intToLogicalBits(y))
|
||||
}
|
||||
|
||||
35 %AND% 42 # 34
|
||||
35 %OR% 42 # 42
|
||||
8
Task/Bitwise-operations/R/bitwise-operations-4.r
Normal file
8
Task/Bitwise-operations/R/bitwise-operations-4.r
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
library(bitops)
|
||||
bitAnd(35, 42) # 34
|
||||
bitOr(35, 42) # 43
|
||||
bitXor(35, 42) # 9
|
||||
bitFlip(35, bitWidth=8) # 220
|
||||
bitShiftL(35, 1) # 70
|
||||
bitShiftR(35, 1) # 17
|
||||
# Note that no bit rotation is provided in this package
|
||||
Loading…
Add table
Add a link
Reference in a new issue