Learn R Programming

MiscMath (version 1.1)

DecToBin: Convert Decimal to Binary

Description

Convert a given decimal constant in the interval (0, 1) to the corresponding binary representation.

Usage

DecToBin(x, m = 32, format = "character")

Value

a vector containing the binary representation

Arguments

x

a numeric vector of values in the interval (0, 1)

m

a numeric constant specifying the number of binary digits to use in the output

format

a character string constant specifying the form of the output

Details

Default format is as a character string. Alternatives are plain which prints results to the device, and vector which output a binary vector.

Examples

Run this code
x <- c(.81, .57, .333) 
DecToBin(x) # character output
DecToBin(x, format="vector") #  binary vector output
DecToBin(x, format="plain") 

Run the code above in your browser using DataLab