number2binary: Convert an integer to fixed-length binary format

View source: R/number2binary.R

number2binaryR Documentation

Convert an integer to fixed-length binary format

Description

This is a wrapper function around intToBits that returns a bit code in fixed-length integer format. The code is based on an SO post by Paul Hiemstra, see https://stackoverflow.com/questions/12088080/how-to-convert-number-into-binary-vector.

Usage

number2binary(number, no_bits, to_char = FALSE)

Arguments

number

An integer to be converted.

no_bits

integer. The desired length of the returned bit code.

to_char

logical. If TRUE, the resulting bit code is returned as merged string.

Value

A bit code in fixed-length integer format or, if to_char, a single character.

Author(s)

Florian Detsch

See Also

intToBits.

Examples

number2binary(10)
number2binary(10, no_bits = 4)
number2binary(10, no_bits = 4, to_char = TRUE)


environmentalinformatics-marburg/Rsenal documentation built on July 28, 2023, 6:09 a.m.