I have the following piece of code that i want to convert what i read in from the text file into a binary representation so i can use it to do encryption.
It currently looks like this:
The test file is am using is already in binary. 00001111
The problem I'm having is a number exception error I can read the file in ok to a string - but when i try to convert the string to an integer with base 2 i get the format error.
My eventual aim is to convert text from a file into binary -> pass that into an encryption algorithm and encrypt. i can do the conversion from text to binary no probs - i just cant get past this number exception error.
This is the output from java. (btw it compiles fine)
C:\sdes>java SdesStart e 0000011111 testfile.txt going to encrypt 100
Exception in thread "main" java.lang.NumberFormatException: For input string: "1 00 " at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at SdesStart.readFile(SdesStart.java:119) at SdesStart.main(SdesStart.java:43)
Joined: Feb 07, 2005
It appears from your output that there is a newline character being read in. Try doing this to remove any white space from the beginning or end of the String before you try to convert it to an int.
Also since you're doing encryption you'll probably want to use large numbers. I would recommend using BigInteger. [ March 25, 2006: Message edited by: Keith Lynn ]