Solved

How to convert BCD codes?

Posted on 2004-03-27
7
1,966 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven example error 3 52
object oriented programming comparison 5 55
map related example 6 36
servlet example 17 0
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…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

895 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

12 Experts available now in Live!

Get 1:1 Help Now