Learn R Programming

rinform (version 1.0.2)

encode: Encode

Description

Encode a base-b array of integers into a single integer. This function uses a big-endian encoding scheme. That is, the most significant bits of the encoded integer are determined by the left-most end of the unencoded state.

Usage

encode(state, b = NA)

Arguments

state

Vector of the state to encode.

b

Numeric giving the base in which to encode.

Value

Numeric giving the encoded state.

Examples

Run this code
# NOT RUN {
# With specified base
encode(c(0, 0, 1), b = 2) # 1
encode(c(0, 1, 0), b = 3) # 3
encode(c(1, 0, 0), b = 4) # 16

# Without specified base
encode(c(0, 0, 2)) # 2
encode(c(0, 2, 0)) # 6
encode(c(1, 2, 1)) # 16
# }

Run the code above in your browser using DataLab