bcd2dec {convertBCD} | R Documentation |
Function to convert binary-coded decimal (BCD) data to decimal form. ~~
Description
Given one or two input vectors of class "raw" , representing an integer and optionally a decimal portion of a number, the decimal values are returned.
Usage
bcd2dec(x, xdec = NULL, mergex = TRUE, endian = c("little", "big"))
Arguments
x |
The vector of bytes containing the BCD representation of the integer portion of a value. Must be of class 'raw'. |
xdec |
The vector of bytes containing the BCD representation of the decimal portion of a value Must be of class 'raw'. The default is |
mergex |
A logical value. If |
endian |
The order of bytes in the raw BCD input. |
Details
The BCD format reserves a full byte for each character (number) in an input value. While this is memory-expensive, it guarantees the exact value is stored, unlike class numeric
or others, which are subject to binary expansion rounding errors.
There is no standard for indicating the location of a decimal point in BCD data, which is why the integer and decimal portion must be entered separately here.
Value
A list with elements:
intx , character strings representing the decimal numbers produced or, if mergex == FALSE
, the integer portions of the numbers.
decx , set to NULL unless mergex == FALSE
, in which case character strings representing the decimal portions of the numbers generated.
Author(s)
Carl Witthoft, carl@witthoft.com
See Also
bcdToInteger
dec2bcd
Examples
foo <- dec2bcd('37.852')
bar <- bcd2dec(foo$xint[[1]],foo$xdec[[1]])