• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BCD to decimal and viceversa

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic