Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

binary2decimal

Binary encoding of decimal numbers and vice versa.


Description

Functions for computing binary to decimal conversion of numbers and vice versa.

Usage

decimal2binary(x, length)
binary2decimal(x)

Arguments

x

input value.

length

an optional value giving the length of binary string to return.

Details

decimal2binary converts a numerical value (which is forced to be an integer) to a binary representation, i.e. a vector of 0s and 1s. For real numerical values see the example below.

binary2decimal converts a binary value, i.e. a vector of 0s and 1s, to a decimal representation.

Author(s)

Luca Scrucca

See Also

Examples

# for integer values
dval <- 12
(bval <- decimal2binary(dval))
binary2decimal(bval)

# for real values
dval <- 12.456
# use
(bval <- decimal2binary(dval*1000))
binary2decimal(bval)/1000

GA

Genetic Algorithms

v3.2.1
GPL (>= 2)
Authors
Luca Scrucca [aut, cre] (<https://orcid.org/0000-0003-3826-0484>)
Initial release
2021-04-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.