Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Binary coded decimal(BCD) libray for nonstop.

128 views
Skip to first unread message

lakshmi gowda

unread,
Jan 5, 2012, 8:42:59 AM1/5/12
to
Hi,
I am seeing on the information on Is there any BCD(Binary coded
decimal) on nonstop or BCD library which is embedded with some other
library/any open source library which we can use on the nonstop
platform for doing the BCD operations. I want to use BCD libray in
embedded SQL application to perform airthmetic/conversion operation
for the bignum data which is in BCD format.

Regards
Lakshmi P S

Randall

unread,
Jan 5, 2012, 9:54:10 AM1/5/12
to
Are you storing BCD in SQL/MX or SQL/MP or just referencing an
external database? Conversion to/from BCD is pretty straightforward as
long as the numbers are fixed size. BCD can be arbitrary if
represented as strings. A sample conversion (use at own risk, signs
not handled, big-endian assumed) is

unsigned long long fromBcd(unsigned long long bcd) {
unsigned long long exp = 1LL;
unsigned long long digit;
unsigned long long result = 0LL;
while (bcd > 0) {
digit = bcd & 0xFLL;
result += digit * exp;
exp *= 10LL;
bcd >>= 4;
}
return result;
}

The reverse is similarly trivial.

Randall

Keith Dick

unread,
Jan 6, 2012, 3:23:52 AM1/6/12
to
Your question is a little unclear or confusing, at least to me. So some of what I write here probably will not be relevant to your problem, and I might not write anything that helps at all, but I will give it a try, based on my guesses about what you are doing. If you need better suggestions, post again with some detailed examples of what you are doing so we can make better suggestions.

BCD and bignum are not the same thing, so I am unsure just what you need. I suppose it is possible that some bignum implementations store the digits two to a byte, as BCD does, but in a quick web search, I could not find anything that documented the actual storage format of any of several bignum libraries.

If you are using COBOL, describing a data field as USAGE COMP-3 declares it as a BCD value. COBOL can use such fields the same as any other numeric field. COMP-3 is limited to 18 digits, which is not bignum, but if all of your data is 18 digits or fewer, COMP-3 would do the job.

I do not know of direct support for BCD in other programming languages supplied by HP for NonStop. I am not familiar with the C++ on NonStop, so there might be a BCD or bignum library supplied as part of that. As Randall pointed out, it is very simple to write your own function to convert between BCD and a regular binary integer. His example is somewhat limited, but a function that handles all the possible BCD forms does not take much more work.

If you really need bignum rather than just BCD, the GNU bignum library is available from the ITUG open source library at:

http://ituglib.connect-community.org/apps/Ituglib/SrchOpenSrcLib.jsf

The package name is gmp. If your bignum data is coming from outside your program, which seems to be the case from what you wrote, I cannot be sure that the gmp package will meet your needs. The data format used by gmp might not match the data format you are receiving.

There are compiled versions of gmp for TNS/R and TNS/E, as well as the source. The compiled versions will be set up to install and use in the OSS environment, so if you are working in OSS, they will be ready to use immediately. If you are working in the Guardian environment, I am not sure how much more work you would have to do to use that package. I imagine there is very little interaction with the operating system in the package, so you might be able to copy the object files from OSS to Guardian and use them with no further change. However, they would have been compiled with the system type as OSS, so they might not be acceptable to be included with an object file compiled as system type Guardian. I cannot remember whether such mixing is permitted or not.

If you cannot use the object files compiled for OSS, you will have to build a version of gmp for the Guardian environment using the source package that is available from the ITUG open source library. I imagine the easiest way would be to modify the make file to add the "systype guardian" option to the compiler options, build in the OSS environment, then move the object files to Guardian. If there are any steps that use the linker, you might have to modify the linker commands. I have never tried building a library in OSS for use in Guardian, so it might not work, but it ought to be pretty easy to try. If you cannot get that to work, the next thing to try would be to move all the files to the Guardian environment and compose manually a command file to compile all the source files and otherwise do the same things that the make file for the package does (but without relying all the automatic magic that make does for you).

As far as I know, neither SQL/MP nor SQL/MX directly supports BCD data or bignum data. That is, there is no column type for declaring a column to contain either of those types of data You probably could put BCD or bignum data into a CHARACTER column. You would not be able to see the numeric values by displaying those columns from the table, but your embedded SQL program could know to treat those columns as BCD or bignum data. I think neither SQL/MP nor SQL/MX check that the contents of a CHARACTER column are valid characters in the declared character set, so I think the non-character data could be safely stored and retrieved. I would not encourage taking that approach, just because it means you cannot use those columns freely in tools like SQLCI or mxci, but I would not argue strongly against it. But if there is some other way to arrange things so that the columns of the SQL tables all contain valid SQL data, that probably would be best in the long run.

Lakshmi P S

unread,
Jan 12, 2012, 11:44:13 AM1/12/12
to
Thanks for explaining. I was just looking for BCD libray which can be
used to do the BCD airthmetic/conversion operation which works on
NONSTOP platform.
0 new messages