?
Solved

How to convert BCD codes?

Posted on 2004-03-27
7
Medium Priority
?
1,975 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Webstorm
ID: 10694504
Hi friendlyarul,

Try this:

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


0
 
LVL 86

Accepted Solution

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

Expert Comment

by:CEHJ
ID: 10702969
8-)
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:friendlyarul
ID: 10703315
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
ID: 10703376
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
ID: 10703684
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
ID: 10703760
8-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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