Examples for 'bitops::bitFlip'


Binary Flip (Not) Operator

Aliases: bitFlip

Keywords: arith utilities

### ** Examples

bitFlip(0:5)
[1] 4294967295 4294967294 4294967293 4294967292 4294967291 4294967290
##
bitUnique <- function(x) bitFlip(bitFlip(x)) # "identity" when x in  0:(2^32-1)
bitUnique(  0:16 ) # identical (well, double precision)
 [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
bitUnique(-(1:16)) # 4294967295 ...
 [1] 4294967295 4294967294 4294967293 4294967292 4294967291 4294967290
 [7] 4294967289 4294967288 4294967287 4294967286 4294967285 4294967284
[13] 4294967283 4294967282 4294967281 4294967280
stopifnot(
  identical(bitUnique(-(1:16)), 2^32 -(1:16)),
  bitFlip(-1) == 0,
  bitFlip(0 ) == 2^32 - 1,
  bitFlip(0, bitWidth=8) == 255
)

[Package bitops version 1.0-9 Index]