Title: | Convert Decimal to Binary-Coded Decimal (BCD) Form and Vice Versa |
---|---|
Description: | Convert BCD (raw bytes) to decimal numbers and vice versa. BCD format is used to preserve decimals exactly, as opposed to the binary rounding errors inherent in "numeric" or "floating-point" formats. |
Authors: | Carl Witthoft [aut, cre] |
Maintainer: | Carl Witthoft <[email protected]> |
License: | LGPL-3 |
Version: | 1.0 |
Built: | 2024-11-26 06:24:19 UTC |
Source: | CRAN |
Convert BCD (raw bytes) to decimal numbers and vice versa. BCD format is used to preserve decimals exactly, as opposed to the binary rounding errors inherent in "numeric" or "floating-point" formats.
The DESCRIPTION file:
Package: | convertBCD |
Type: | Package |
Title: | Convert Decimal to Binary-Coded Decimal (BCD) Form and Vice Versa |
Version: | 1.0 |
Date: | 2024-06-24 |
Authors@R: | c(person(given = "Carl", family = "Witthoft", role = c("aut","cre"), email= "[email protected]")) |
Description: | Convert BCD (raw bytes) to decimal numbers and vice versa. BCD format is used to preserve decimals exactly, as opposed to the binary rounding errors inherent in "numeric" or "floating-point" formats. |
License: | LGPL-3 |
Imports: | Rmpfr, gmp, methods |
NeedsCompilation: | no |
Packaged: | 2024-06-28 11:50:35 UTC; cgw |
Author: | Carl Witthoft [aut, cre] |
Maintainer: | Carl Witthoft <[email protected]> |
Repository: | CRAN |
Date/Publication: | 2024-06-28 15:00:02 UTC |
Config/pak/sysreqs: | libgmp3-dev libmpfr-dev |
Index of help topics:
bcd2dec Function to convert binary-coded decimal (BCD) data to decimal form. ~~ convertBCD-package Convert Decimal to Binary-Coded Decimal (BCD) Form and Vice Versa dec2bcd Convert decimal numbers to binary-coded decimal (BCD) form. ~~ ~~
Carl Witthoft [aut, cre]
Maintainer: Carl Witthoft <[email protected]>
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.
bcd2dec(x, xdec = NULL, mergex = TRUE, endian = c("little", "big"))
bcd2dec(x, xdec = NULL, mergex = TRUE, endian = c("little", "big"))
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. |
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.
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.
Carl Witthoft, [email protected]
bcdToInteger
dec2bcd
foo <- dec2bcd('37.852') bar <- bcd2dec(foo$xint[[1]],foo$xdec[[1]])
foo <- dec2bcd('37.852') bar <- bcd2dec(foo$xint[[1]],foo$xdec[[1]])
The input decimal values are converted to one or two vectors of class "raw" , representing an integer and optionally a decimal portion of a number.
dec2bcd(x, endian = c("little", "big"))
dec2bcd(x, endian = c("little", "big"))
x |
Decimal numbers. Can be one of the following classes: numeric, bigz, character. |
endian |
The order of bytes desired in the raw BCD output. |
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 are returned separately. .
A list containing: intx , a vector of strings representing the integer parts of the decimal number decx, a vector of strings representing the decimal parts of the decimal number, if any.
Carl Witthoft, [email protected]
foo <- dec2bcd('37.852') bar <- bcd2dec(foo$xint[[1]],foo$xdec[[1]])
foo <- dec2bcd('37.852') bar <- bcd2dec(foo$xint[[1]],foo$xdec[[1]])