0:255
. For (file) storage, these can be packed into 32 bit
integers. These functions are for packing and unpacking.pack8bit(v8)
unpack8bit(v)
pack8bit(v8)
returns an integer vector of length
ceiling(length(v8) / 4)
. unpack8bit(v)
returns a vector of values from 0:255
of
length 4 * length(v)
.
v8
is not a multiple of 4, v8
is effectively padded with one to three 0
s.The implementation is straightforward and short; look at the function definitions.
compress
etc for wavelet compression.pack8bit(0:11)
(pack8bit(0:11) == pack8bit(0:9))# both need 3 32-bit ints; only 1st is =
## BUG:
all(250:255 == unpack8bit(pack8bit(250:255)))
stopifnot(0:255 == unpack8bit(pack8bit(0:255)))
Run the code above in your browser using DataLab