Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

signedIntToNybble

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 singleintger 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()

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

ProTrackR

Manipulate and Play 'ProTracker' Modules

v0.3.7
GPL-3
Authors
Pepijn de Vries [aut, cre, dtc]
Initial release
2020-02-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.