base {EnvStats}R Documentation

Base bb Representation of a Number

Description

For any number represented in base 10, compute the representation in any user-specified base.

Usage

  base(n, base = 10, num.digits = max(0, floor(log(n, base))) + 1)

Arguments

n

a non-negative integer (base 10).

base

a positive integer greater than 1 indicating what base to represent n in.

num.digits

a positive integer indicating how many digits to use to represent n in base base. By default, num.digits is equal to just the number of required digits (i.e., max(0, floor(log(n, base))) + 1). Setting num.digits to a larger number than this will result in 0's padding the left.

Details

If bb is a positive integer greater than 1, and nn is a positive integer, then nn can be expressed uniquely in the form

n=akbk+ak1bk1++a1b+a0n = a_kb^k + a_{k-1}b^{k-1} + \ldots + a_1b + a0

where kk is a non-negative integer, the coefficients a0,a1,,aka_0, a_1, \ldots, a_k are non-negative integers less than bb, and ak>0a_k > 0 (Rosen, 1988, p.105). The function base computes the coefficients a0,a1,,aka_0, a_1, \ldots, a_k.

Value

A numeric vector of length num.digits showing the representation of n in base base.

Note

The function base is included in EnvStats because it is called by the function
oneSamplePermutationTest.

Author(s)

Steven P. Millard (EnvStats@ProbStatInfo.com)

References

Rosen, K.H. (1988). Discrete Mathematics and Its Applications. Random House, New York, pp.105-107.

See Also

oneSamplePermutationTest.

Examples

  # Compute the value of 7 in base 2.

  base(7, 2) 
  #[1] 1 1 1 

  base(7, 2, num.digits=5) 
  #[1] 0 0 1 1 1

[Package EnvStats version 2.8.1 Index]