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 integer value or a vector of integer data ranging from -8 up to 7.

which

A character string indicating whether the nybble should be set to the "low" (default) or "high" position of the raw data that is returned.

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 integers.

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")

[Package ProTrackR version 0.4.3 Index]