Skip to contents

Convert Integers to Numeral System

Usage

intToNumeralSystem(x, base)

Arguments

x

vector of integers

base

base of the numeral system

Value

matrix with as many rows as there are elements in x and as many columns as digits that are required to represent the integers in

x in the numeral system in base base. The elements of

x appear as row names whereas the powers of base appear as column names.

Examples

intToNumeralSystem(1:16, base = 2) # binary system
#>    16 8 4 2 1
#> 1   0 0 0 0 1
#> 2   0 0 0 1 0
#> 3   0 0 0 1 1
#> 4   0 0 1 0 0
#> 5   0 0 1 0 1
#> 6   0 0 1 1 0
#> 7   0 0 1 1 1
#> 8   0 1 0 0 0
#> 9   0 1 0 0 1
#> 10  0 1 0 1 0
#> 11  0 1 0 1 1
#> 12  0 1 1 0 0
#> 13  0 1 1 0 1
#> 14  0 1 1 1 0
#> 15  0 1 1 1 1
#> 16  1 0 0 0 0
intToNumeralSystem(1:16, base = 10) # decimal system
#>    10 1
#> 1   0 1
#> 2   0 2
#> 3   0 3
#> 4   0 4
#> 5   0 5
#> 6   0 6
#> 7   0 7
#> 8   0 8
#> 9   0 9
#> 10  1 0
#> 11  1 1
#> 12  1 2
#> 13  1 3
#> 14  1 4
#> 15  1 5
#> 16  1 6
intToNumeralSystem(1:16, base = 8) # octal system
#>    8 1
#> 1  0 1
#> 2  0 2
#> 3  0 3
#> 4  0 4
#> 5  0 5
#> 6  0 6
#> 7  0 7
#> 8  1 0
#> 9  1 1
#> 10 1 2
#> 11 1 3
#> 12 1 4
#> 13 1 5
#> 14 1 6
#> 15 1 7
#> 16 2 0