These functions convert numbers from one base to another. There are several solutions for this problem out there, but the naming is quite heterogeneous and so consistent function names might be helpful.

BinToDec(x)
DecToBin(x)
OctToDec(x)
DecToOct(x)
HexToDec(x)
DecToHex(x)

Arguments

x

a vector of numbers, resp. alphanumerical representation of numbers (hex), to be converted.

Details

BinToDec converts numbers from binary mode into decimal values. DecToBin does it the other way round.
Oct means octal system and hex hexadecimal.

Value

A numeric or character vector of the same length as x containing the converted values. Binary, octal and decimal values are numeric, hex-values are returned as class hexmode.

Author

Andri Signorell <andri@signorell.net>

See also

Examples

DecToBin(c(17, 25))
#> [1] "10001" "11001"
BinToDec(c(101, 11101))
#> [1]  5 29

DecToOct(c(17, 25))
#> [1] 21 31
OctToDec(c(11, 77))
#> [1]  9 63

DecToHex(c(17, 25))
#> [1] "11" "19"
HexToDec(c("FF", "AA", "ABC"))
#> [1]  255  170 2748