binary2decimal: Binary encoding of decimal numbers and viceversa.

Description Usage Arguments Details Author(s) See Also Examples

View source: R/miscfun.R

Description

Functions for computing binary to decimal conversion of numbers and viceversa.

Usage

1
2

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.

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

Author(s)

Luca Scrucca

See Also

binary2gray

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 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 documentation built on May 30, 2017, 5:35 a.m.