inttostr {Rstreams}R Documentation

Converts Integers to Strings in Different Bases

Description

Converts an integer to a string representation in base 2 to 36.

Usage

  inttostr(x, digits = 0, base = 16, complement = FALSE))

Arguments

x a vector of integers to display
digits the minimum number of digits to use
base the numeric base of the representation
complement whether to keep the sign on negatives or use a complement display

Details

All of the integers in x will be converted using the same number of digits.

If complement=TRUE, then instead of keeping negative signs, all negative values will have base^digits added. In order for this scheme to produce unique strings, base^digits/2 must be bigger than the largest number. If this is not the case, then complements will not be taken.

See the examples.

Value

a character vector giving the representation of each integer

Examples

# Display using signed notation, with leading zeros
inttostr(c(-1,1), 4)
# Display using complement notation
inttostr(c(-1,1), 4, complement=TRUE)