Learn R Programming

asbio (version 1.11)

bin2dec: Conversion between binary digits and decimal numbers

Description

The function bin2dec Converts binary representations to digital numbers (e.g., 10101011 = 171). Fractions, (e.g., 0.11101) will be evaluated to the number of bits provided. The function will not handle codification of whole numbers with fractional parts. The function dec2bin Converts decimal representations to binary and can handle whole numbers, fractional, and numbers with both whole and fractional parts.

Usage

bin2dec(digits, round = 4)

dec2bin(num, max.bits = 10, max.rep0 = 6)

Arguments

digits

A string of binary digits.

round

Rounding for fractional results, defaults to 4.

num

A decimal number.

max.bits

The maximum number of bits to be used to approximate fractional numbers.

max.rep0

A handler for meaningless repeating zeroes at the end of some binary representations of decimal numbers, e.g., 0.25. Can be turned off by letting max.rep0 = NULL.

Author

Ken Aho

Details

If a decimal number with fractional, or both whole and fractional parts is provided to dec2bin, a vector with seperate binary expressions for each of these components is returned.

Examples

Run this code
bin2dec(1011001101) #=717
dec2bin(717)

Run the code above in your browser using DataLab