File: bitops.R

package info (click to toggle)
r-cran-bitops 1.0-9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 148 kB
  • sloc: ansic: 231; sh: 13; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download | duplicates (2)
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
## MM:  the "x <- a - a" (== integer(n)) and then
## ---      "x <- x + .C(...)"
## is probably for safety, normalization of unsigned int
## -- and for NA/NaN handling -- but that is done too complicated here.
##--- and: If I really want pack bits into integers,
##--- I cannot really deal with NA-bits in such a way!
##---> I'd need extra structure to store NA locations...
##
## OTOH: instead of CLASSES & COPY, we should use .Call() !!

bitFlip <- function(a,bitWidth=32)
{
    .Call(C_bitFlip, a, bitWidth)
}


`%&%` <-
bitAnd <- function(a, b)
{
    .Call(C_bitAnd, a, b)
}


`%|%` <-
bitOr <- function(a, b)
{
    .Call(C_bitOr, a, b)
}

`%^%` <-
bitXor <- function(a, b)
{
    .Call(C_bitXor, a, b)
}

`%<<%` <-
bitShiftL <- function(a, b)
{
    .Call(C_bitShiftL, a, b)
}

`%>>%` <-
bitShiftR <- function(a, b)
{
    .Call(C_bitShiftR, a, b)
}


cksum <- function(a)
{
    x <- nchar(as.character(a))*0
    x <- x + .C(C_cksum, # ../src/cksum.c
                length(a), as.character(a),
                val = as.numeric(x),
		NAOK=TRUE)$val
    x[is.na(a)] <- NA
    x
}