• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BCD to decimal and viceversa

 
Prashanth Babu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

TIA,
Prashanth Babu.
 
Henry Wong
author
Marshal
Pie
Posts: 21437
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic