-
Notifications
You must be signed in to change notification settings - Fork 45
/
bcdd.doc
92 lines (74 loc) · 3.45 KB
/
bcdd.doc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---------------------------------------------------------------
bcd_to_double()
---------------------------------------------------------------
NAME:
bcd_to_double() - Converts a binary coded decimal value to type double.
SYNOPSIS:
#include "toolbox.h"
double bcd_to_double( void *buf, unsigned length, int digits );
DESCRIPTION:
The bcd_to_double() function will convert a buffer containing binary
coded values to a value of type double. Binary coded decimal values
are typically data downloaded from a mainframe type computer.
ARGUMENTS:
void *buf - Address of buffer containing binary coded value.
unsigned length - The length of the buffer.
int digits - The number of digits to the right of the decimal
point.
RETURN VALUE:
A value of type double.
EXAMPLE:
#include <stdio.h>
double bcd_to_double( void *buf, unsigned length, int digits );
int main ( void ) {
double rv;
char test1[] = { 0x00, 0x12, 0x34, 0x5c };
char test2[] = { 0x00, 0x12, 0x34, 0x56, 0x7d };
printf( "%.2f\n", bcd_to_double( test1, sizeof(test1), 0));
printf( "%.2f\n", bcd_to_double( test2, sizeof(test2), 2));
return 0;
}
---------------------------------------------------------------
double_to_bcd()
---------------------------------------------------------------
NAME:
double_to_bcd() - Converts a value of type double to Binary Coded
Decimal format.
SYNOPSIS:
#include "toolbox.h"
int double_to_bcd(double arg, char *buf, unsigned len, unsigned digits);
DESCRIPTION:
The double_to_bcd() function converts a numeric value of type double
to a signed binary coded decimal format used by IBM mainframe
computers. The function allows the number of decimal digits to be
specified as well as the number of significant digits to be
specified. The resulting binary coded decimal value is adjusted
according to the position, if any, of the decimal point.
ARGUMENTS:
double arg - The numeric double value to be converted.
char *buf - The address of a buffer where the BCD format is to
be stored.
unsigned len - The number of significant digits to be stored.
unsigned digits - The number of decimal digits to be stored.
RETURN VALUE:
An integer value indicating the packed length of the BCD value. A
-1 is returned if the value can not be converted. Reasons for a
conversion failure are: (1) Both the len and digits arguments are
zero, or (2) The sum of the len and digits arguments is greater than
the number of significant digits that can be respresented by a value
of type double. This value is specified by the manifest constant
DBL_DIG in the standard header file float.h.
SEE ALSO:
bcd_to_double()
EXAMPLE:
Double Length Digits Return
Argument Argument Argument Value Buffer
===================================================================
12345.670 0 0 -1 Undetermined
12345.670 5 0 3 12 34 5C
12345.670 5 1 4 01 23 45 6C
12345.670 4 3 4 23 45 67 0C
12345.678 1 2 2 56 7C
-12345.000 8 2 6 00 00 12 34 50 0D
-1234.560 5 3 5 00 12 34 56 0D
1234.567 1 3 3 04 56 7C