Solved

# JAVA how to use asciiToBinary function

Posted on 2006-05-09
Medium Priority
246 Views
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
Question by:cottyengland
• 4
• 3

LVL 92

Expert Comment

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

Author Comment

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

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

Author Comment

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

Author Comment

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

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

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

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