Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to convert BCD codes?

Posted on 2004-03-27
7
Medium Priority
?
1,978 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
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!

 

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

Industry Leaders: 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

609 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