Learn R Programming

rinform (version 1.0.2)

decode: Decode

Description

Decode an integer into a base-b array with n digits. Note that the base b must be provided, but the number of digits n is optional. If it is provided then the decoded state will have exactly that many elements. If n is not provided, the length of the decoded state is as small as possible.

Usage

decode(encoding, b, n = NA)

Arguments

encoding

Numeric of the encoded state.

b

Numeric giving the desired base.

n

Numeric giving the desired number of digits.

Value

Vector giving the decoded state.

Examples

Run this code
# NOT RUN {
# The provided encoded state is decoded using the big-endian
# encoding scheme.
decode(2, b = 2, n = 2) # [1, 0]
decode(6, b = 2, n = 3) # [1, 1, 0]
decode(6, b = 3, n = 2) # [2, 0]

# If n is not provided, the length of the decoded state
# is as small as possible
decode(1, b = 2) # [1]
decode(1, b = 3) # [1]
decode(3, b = 2) # [1, 1]
decode(3, b = 3) # [1, 0]
decode(3, b = 4) # [3]

# }

Run the code above in your browser using DataLab