Results 1 to 12 of 12
Thread: decode binary to characters
- 04-14-2010, 11:40 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 7
- Rep Power
- 0
decode binary to characters
Hey guys i just need a little help, i have created a java program to read binary from an external file eg, input.txt, and the notation is as follows 00000001 00000100 so all the binary is on one line separated by a space, now my program currently reads the binary values and prints them onto the screen, which is fine, the part which trouble me is decoding the binary to become a character, so the user can find out the "secret message". can anyone provide help with this. Thanks
- 04-14-2010, 07:28 PM #2
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
What exactly have you tried? Or are you having problems trying to figure out how to go about this?
- 04-14-2010, 07:33 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Which encoding you use, base64?
- 04-14-2010, 10:21 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 7
- Rep Power
- 0
@ StormyWaters
Nope i am having problems trying to figure out the notation so the binary can be translated to ASCII
@ Eranga
01000001 01000010 01000011 00001010 01000100 01000101 01000110 00001010 00110000 00110001 00110010 00110011
for example this bit of binary is supposed to display
ABC
DEF
0123
so its binary to ASCII
- 04-14-2010, 10:40 PM #5
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
for example lets use binary "10100011010010" thats is code for character "?".
first change it from String to Integer:
int code = Integer.parseInt("10100011010010",2);
second: cast it from Integer to Char:
System.out.println((char)code);
little program:
Java Code:public class binaryToChar { public static void main(String[] args) { int code = Integer.parseInt("10100011010010",2); System.out.println((char)code); } }
- 04-15-2010, 02:43 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Then, how you define the binary stream length?
- 04-15-2010, 02:48 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-15-2010, 09:30 AM #8
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
Yes, you're right.Java Code:Try following code segments, you found two things.
I fix it.
Java Code:public class binaryToChar { public static void main(String[] args) { int code = Integer.decode("10100011"); System.out.println((char)code); } }
- 04-15-2010, 04:41 PM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's much better. We'll see out thread starters' comment.
- 04-16-2010, 01:07 PM #10
Member
- Join Date
- Apr 2010
- Posts
- 7
- Rep Power
- 0
This solution works
however how can i get this program to convert binary numbers from a txt document? here an example documentJava Code:public class binaryToChar { public static void main(String[] args) { int code = Integer.parseInt("10100011010010",2); System.out.println((char)code); } }
- 04-16-2010, 02:54 PM #11
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
I suggest you first try to read a file. See if you can successfully read the file and print it out as is, then try to translate it.
Here's a Tutorial that will help:
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
- 04-17-2010, 03:48 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yeah, step down your problem first of all and solve them step by step. I think you get enough comments on conversion you want. If you go through them carefully it's possible to find the solution. So give a try from the first step and let us know if you stuck with any. Your effort make a real change lol.
Similar Threads
-
Decode this piece of Code
By mikeyl62 in forum New To JavaReplies: 2Last Post: 02-27-2010, 08:59 PM -
code and decode?
By jeffrey in forum New To JavaReplies: 5Last Post: 08-07-2009, 09:18 AM -
Getting problem in UTF-8 Encode/Decode with Java
By sagarsway in forum Advanced JavaReplies: 2Last Post: 12-22-2008, 07:01 PM -
allowable characters from URLDecoder.decode(String
By Nicholas Jordan in forum NetworkingReplies: 4Last Post: 10-18-2008, 05:46 PM -
MimeUtility.decode encoding
By mwildam in forum Advanced JavaReplies: 2Last Post: 08-19-2008, 02:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks