showHex

0th

Percentile

Show numbers in binary and hex format

Show numbers in binary and hex format.

Keywords
classes, arith
Usage
showHex(x, ...)
## hexdigits is the number of hex digits after the precision point

showBin(x, ..., shift=FALSE, LeftPad="_", RightPad="_") ## bindigits is number of binary digits after the precision point

## not exported showHexInternal(x, bindigits=if (is(x, "mpfr")) min(Rmpfr::.getPrec(x)) else Rmpfr::mpfr_default_prec(), hexdigits=1 + ((bindigits-1) %/% 4), ...)

Arguments
x
x
bindigits
Number of binary digits after the binary point.
hexdigits
Number of hexadecimal digits after the hexadeximal point.
shift
Logical. When FALSE (the default) the binary representation is displayed in scientific notation (3 is displayed as +0b1.1000p+1). When TRUE, the binary representation is in regulat format shifted to align bin
...
The specifications bindigits and hexdigits are the only optional arguments that will be used.
LeftPad, RightPad
Characters that will be used for left- and right-padding of the formatted string when shift=TRUE.
Details

For the hexadecimal representation, the function sprintf is used directly. For the binary representation, the hexadecimal value is calculated and then edited by substitution of the binary representation of the hex characters coded in the HextoBin vector.

Value

  • A character matrix containing the formatted represention of the argument. Arithmetic cannot be done on the result.

References

R FAQ 7.31: Why doesn't R think these numbers are equal? system.file("../../doc/FAQ")

See Also

mpfr, sprintf

Aliases
  • showHex
  • showBin
  • showHexInternal
  • HextoBin
  • BintoHex
  • Bintohex
Examples
FourBits <- Rmpfr::mpfr(matrix(0:31, 8, 4), precBits=4) ## 4 significant bits
dimnames(FourBits) <- list(0:7, c(0,8,16,24))
FourBits

showHex(FourBits)
showBin(FourBits)
showBin(FourBits, shift=TRUE)

showBin(FourBits, bindigits=3) ## 3 digits after the binary point
showBin(FourBits, bindigits=3, shift=TRUE)

showHex(FourBits, bindigits=6)
showHex(FourBits, hexdigits=2)

showBin(FourBits, bindigits=6)
showBin(FourBits, shift=TRUE, bindigits=6)
showBin(FourBits, hexdigits=2)
Documentation reproduced from package HH, version 3.1-19, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.