signedIntToNybble {ProTrackR} | R Documentation |
Convert a signed integer to a nybble in raw data.
Description
This function converts a signed integer ranging from -8 up to 7 into
either the high or low nybble of a byte, represented by raw
data.
Usage
signedIntToNybble(int_dat, which = c("low", "high"))
Arguments
int_dat |
A single |
which |
A character string indicating whether the nybble should
be set to the |
Details
Nybbles are 4 bit values, where each byte (8 bits) holds two nybbles.
A high nybble (left-hand side of a byte) and a low nybble (right-hand
side of a byte). This function converts a signed integer
value
ranging from -8 up to 7 to a nybble and sets it as either a high or a low
nybble in raw
data.
Value
Returns raw
data of the same length as int_dat
.
The returned raw data holds either low or high nybbles (as specified
by which
) based on the provided signed integer
s.
Author(s)
Pepijn de Vries
See Also
Other nybble.functions:
nybbleToSignedInt()
,
nybble()
Other raw.operations:
as.raw()
,
nybbleToSignedInt()
,
nybble()
,
rawToCharNull()
,
rawToPTModule()
,
rawToSignedInt()
,
rawToUnsignedInt()
,
signedIntToRaw()
,
unsignedIntToRaw()
Other integer.operations:
nybbleToSignedInt()
,
nybble()
,
rawToSignedInt()
,
rawToUnsignedInt()
,
signedIntToRaw()
,
unsignedIntToRaw()
,
waveform()
Examples
## generate some integers in the right range:
dati <- sample(-8:7, 100, replace = TRUE)
## Set the low nybbles of rawl based on dati:
rawl <- signedIntToNybble(dati)
## Set the high nybbles of rawl based on dati:
rawh <- signedIntToNybble(dati, "high")