flip_endian: Flip the endianness of elements in a vector

View source: R/endian.R

flip_endianR Documentation

Flip the endianness of elements in a vector

Description

This will create a new vector with the values reversed within the given block size. This can be used for changing the endianness of a set of values

Usage

flip_endian(x, size)

Arguments

x

vector. Usually a raw vector, but can be any type

size

block size. Usually a power of 2.

Value

A vector of the same type as the initial vector with the values within each block reversed.

See Also

Other data permutation functions: aperm_array_to_vector(), aperm_vector_to_array()

Examples

vec <- c(1, 2, 3, 4)
flip_endian(vec, 1)   # should give: c(1, 2, 3, 4)
flip_endian(vec, 2)   # should give: c(2, 1, 4, 3)
flip_endian(vec, 4)   # should give: c(4, 3, 2, 1)

ctypesio documentation built on April 3, 2025, 7:28 p.m.