bitFlip(0:5)
##
bitUnique <- function(x) bitFlip(bitFlip(x)) # "identity" when x in 0:(2^32-1)
bitUnique( 0:16 ) # identical (well, double precision)
bitUnique(-(1:16)) # 4294967295 ...
stopifnot(
identical(bitUnique(-(1:16)), 2^32 -(1:16)),
bitFlip(-1) == 0,
bitFlip(0 ) == 2^32 - 1,
bitFlip(0, bitWidth=8) == 255
)
Run the code above in your browser using DataLab