bits: Binary Representation

Description Usage Arguments Details Value See Also Examples

View source: R/bits.R

Description

Literal bit representation.

Usage

1
bits(x, k = 54, pos_sign = FALSE, break0 = FALSE)

Arguments

x

a positive or negative floating point number.

k

number of binary digits after the decimal point

pos_sign

logical; shall the '+' sign be included.

break0

logical; shall trailing zeros be included.

Details

The literal bit/binary representation of a floating point number is computed by subtracting powers of 2.

Value

Returns a string containing the binary representation.

See Also

nextpow2

Examples

1
2
3
4
5
bits(2^10)        # "10000000000"
bits(1 + 2^-10)   #  "1.000000000100000000000000000000000000000000000000000000"
bits(pi)          # "11.001001000011111101101010100010001000010110100011000000"
bits(1/3.0)       #  "0.010101010101010101010101010101010101010101010101010101"
bits(1 + eps())   #  "1.000000000000000000000000000000000000000000000000000100"

Example output

[1] "10000000000"
[1] "1.000000000100000000000000000000000000000000000000000000"
[1] "11.001001000011111101101010100010001000010110100011000000"
[1] "0.010101010101010101010101010101010101010101010101010101"
[1] "1.000000000000000000000000000000000000000000000000000100"

pracma documentation built on Dec. 11, 2021, 9:57 a.m.