# formatHex

From HH v3.1-23
0th

Percentile

##### Format numbers in binary and hex and decimal format, and scan binary and hex.

Format numbers in binary and hex and decimal format, and scan binary and hex. This is an early version of functions which will eventually be in Rmpfr.

Keywords
classes, arith
##### Usage
formatHex(x, ...)formatBin(x, precBits=min(getPrec(x)), scientific=TRUE,
nsmall=NULL, scientific=FALSE, ...)scanBin(x, precBits=stop("Must specify precBits.", call.=FALSE), scientific=TRUE)scanHex(x, precBits=NULL)## not exported
formatHexInternal(x, precBits=min(Rmpfr::getPrec(x)), ...)
##### Arguments
x
For the formatXXX functions, any numeric or mpfr object. For the scanXXX functions, the result of a previous formatXXX function.
precBits
Number of bits of precision. The default value is the number returned by Rmpfr::mpfr_default_prec() Double precision numbers have 53 bits. For more detail, see mpfr.

For the

scientific
Logical. When TRUE (the default) formatBin will display the binary representation in scientific notation (mpfr(3, 5) is displayed as +0b1.1000p+1). When FALSE, formatBin
...
Additional arguments. formatHexInternal, formatHex, formatBin: precBits is the only ... argument acted on. Other ... arguments are ignored.

formatDec: pr

Characters that will be used for left- and right-padding of the formatted string when shift=TRUE.
digits, nsmall
arguments forwarded to format.
##### 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. For binary with shift=TRUE, the result of the shift=FALSE version is edited to align binary points. For the decimal representation, the hexadecimal value is calculated with the specified precision and then sent to the format function for scientific=FALSE or to the sprintf function for scientific=TRUE.

scanBin reads the output of formatBin. scanHex reads the output of formatHex.

##### Value

• For the formatXXX functions, a character matrix containing the formatted represention of the argument. Arithmetic cannot be done on the result.

For the scanXXX functions, a mpfr object containing the value of the argument.

##### References

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

mpfr, sprintf

##### Aliases
• formatHex
• formatBin
• formatDec
• scanHex
• scanBin
• formatHexInternal
• 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

formatHex(FourBits)
formatBin(FourBits)
formatBin(FourBits, shift=TRUE)
formatDec(FourBits)

FBB <- formatBin(FourBits)
scanBin(FBB, precBits=4)

FBH <- formatHex(FourBits)
scanHex(FBH)

TenFrac <- matrix((1:10)/10, dimnames=list(1:10, expression(1/x)))
TenFrac9 <- Rmpfr::mpfr(TenFrac, precBits=9) ## 9 significant bits
TenFrac9
formatHex(TenFrac9)
formatBin(TenFrac9)
formatBin(TenFrac9, shift=TRUE)
formatDec(TenFrac9)
formatDec(TenFrac9, precBits=10)
Documentation reproduced from package HH, version 3.1-23, License: GPL (>= 2)

### Community examples

Looks like there are no examples yet.