Solved

How to convert BCD codes?

Posted on 2004-03-27
7
1,964 Views
Last Modified: 2007-12-19
Hai,

I want to know about,
How to convert the Strings to Binary Code Decimal(BCD Code)?

0
Comment
Question by:friendlyarul
  • 4
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Webstorm
Comment Utility
Hi friendlyarul,

Try this:

  byte[] b=str.getBytes("EBCDIC");


0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
Comment Utility
String s = "1234567890";
byte[] bytes = s.getBytes("Cp500");
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:friendlyarul
Comment Utility
Hai,

I'm using ur concept to convert the string into byte codes. But i'm not satisfied with this concept, because of this, the length of the answer is too short. Even after giving a lengthy string value the  answer falls within 9 to 10 characters. i.e., max length of the answer is 9 or 10. And If i give small string value also it gives the max length of the answer 9 to 10.

Converting EBCDIC Program:
----------------------------------

class ConvertBcd{
     public static void main(String[] argv){
        try
        {
           String str = "ARULKUMAR";
           byte b[] = str.getBytes();
           System.out.println("\n"+str + " is converted into EBCDIC code : " + b);

           String cvt = "1200";
           byte[] cot= cvt.getBytes();
           System.out.println("\n"+cvt+ " is converted into EBCDIC code : " + cot);

         String x="5499990123456781D09081015432198712345";
         byte y[] = x.getBytes();
         System.out.println("\n"+x + " is converted into EBCDIC code : " + y);
        }
        catch(Exception e){
      System.out.println("EBCDIC Exception is:  " + e);
         }      
    }
}

This is the prg. i wrote for converting string into EBCDIC.

Output of this prg:
---------------------
 
1200 is converted into EBCDIC code :  [B@f5da06

This is one of the answer, it returns. See, in this prg. i'm using three diffrent types of input strings. But it returns the same length of answers. Am not able to understand this type of answers, becasue i'm declaring the third string to be lengthy.

ok fine, i think u understood my prob. pls. reply me ASAP.

Regards,

Friendly Arul.
 
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Your code doesn't seem to be related to the code i posted. All you're doing is converting a String to a byte array and then printing the reference of your byte array.

What you should be doing is this:

String str = "ARULKUMAR";
byte b[] = str.getBytes("Cp500");
System.out.println("\n"+str + " is converted into EBCDIC code : ");
System.out.println(new sun.misc.HexDumpEncoder().encode(b));

0
 

Author Comment

by:friendlyarul
Comment Utility
Hai,

"Good Answer"

Now i done this program successfully. Thanks for ur immediate response for my words.

Regards,

Friendly Arul.


0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bigHeights  challenge 13 55
powerN  challenge 3 46
Updating Java 9 86
where is session ID cache stored 1 38
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now