?
Solved

JAVA how to use asciiToBinary function

Posted on 2006-05-09
8
Medium Priority
?
246 Views
Last Modified: 2008-01-16
How can I convert an ascii character (a-z and 0-9) to an 8 bit binary string?

for example ascii 2  = binary 00110010 and ascii S = binary 01010011

Thank You
0
Comment
Question by:cottyengland
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16643612
String binary = Integer.toBinaryString((int)c);
0
 

Author Comment

by:cottyengland
ID: 16643741
String cage2_b = Integer.toBinaryString('S'); works!

String cage2_b = Integer.toBinaryString('2'); or String cage2_b = Integer.toBinaryString(2); does not work.

Almost there...
0
 
LVL 92

Expert Comment

by:objects
ID: 16643796
> String cage2_b = Integer.toBinaryString('2'); or String cage2_b = Integer.toBinaryString(2); does not work.

why doesn''t the first one work? what result are you getting?
the 2nd will give you the binary string for the value 2, not the ascii value of the character 2

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:cottyengland
ID: 16643816
Sorry, I know understand that I am supposed to use the ascii decimal value.
0
 

Author Comment

by:cottyengland
ID: 16643870
Well I thought I was getting it but know I am not so sure. I do not know the decimal value of the ascii character '2'. Back to the original question...How do I convert the ascii character of '2' to its binary value?

 
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16643917
String binary = Integer.toBinaryString((int)'2');

http://www.micron.com/k12/lessonplans/zerosones/asciibinary.html
0
 

Author Comment

by:cottyengland
ID: 16644001
OK Great.. jow I get it! I just posted a related question. maybe you can help there also?

Thank You

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21844378.html
0

Featured Post

Technology Partners: 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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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.
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

829 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