Solved

How to convert BCD codes?

Posted on 2004-03-27
7
1,969 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
ID: 10694504
Hi friendlyarul,

Try this:

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


0
 
LVL 86

Accepted Solution

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

Expert Comment

by:CEHJ
ID: 10702969
8-)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 46
jsp login check 12 43
Cisco ASA: Java web start no go, asdm launcher no go 3 37
Tagging and Merging on Branch 1 30
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 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