Hi, Am working on conversion of decimal to BCD (Binary coded decimal) and viceversa. I require BCD for calling Cobol from Java using JNI. Can anybody help me out in giving a pointer or an algorithm for doing the same. I Googled on the web for any info on BCD conversion, but all in vain. Please help me out.
It has been years since I did this, but I am surprised that you could not find anything with google. BCD is simply the representation of decimal digits in 4 bits each... For example...
Number 42 ---> digit 4 is "0100" and digit 2 is "0010" ---> "01000010" in BCD. Just pull each decimal digit off, convert to 4 bits, and concat it back.
I'm no expert, COBOL was a bit before my time, but I think the BCD used is packed in some way. It might be worth checking, then searching the web for "Comp-3". I don't think it's drastically difficult to do the conversion, and I expect that someone has faced the same problem as you before.
We've talked about packed decimal before. Don't know if I maybe posted a running solution once. Use the ranch search on the three Java in General forums.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
a bit of art, as a gift, the permaculture playing cards