Skip to contents

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.

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.

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.

Author

Pepijn de Vries

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