baseConvert: Number Base Conversion

View source: R/baseConvert.R

baseConvertR Documentation

Number Base Conversion

Description

Converts numbers from one base to another.

Usage

baseConvert(x, target, base = 10)

Arguments

x

number to convert. If base is greater than 10, x must be mode character. Otherwise, numeric is allow.

target

target base to convert x to.

base

starting base of x.

Details

Uses multiplication to convert the number to base 10 and integer division and modulo to convert that to the target base. The starting and target bases must be in the range [2,36].

Value

Character representation of the number in the new base.

Examples

baseConvert(231, 16)
baseConvert(231, 2)
baseConvert("7A", 10, 16)
baseConvert("100110110", 10, 2)

graywh/r-gmisc documentation built on April 19, 2023, 1:42 p.m.