John Gable

Greenhorn
+ Follow
since Apr 12, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Gable

So how to i get the integer to store 00001111 ??
18 years ago
Ok I've done some checking.

The original code i was using was this:



This is the code i modified to check what was being passed in.



Looking at the result from the 2nd one:

value of answer: 585
value of decrypted answer: -21
inside decrypt for printb


that means it's not passing in the 00001111 that i want - but 585.
not sure where 585 is coming from tho ?
18 years ago
I'm trying to do an encryption algorithm - for the decryption it requires 8 bits -> if i pass in only 6 as in this example it doesnt like it.
18 years ago
Hey,

I'm trying to convert a 8 bit string of binary into an integer.
I do this by



Only problem is it drops the leading zeros.
eg if the string rep was 00111001 then after parsing the Integer represents 111001 -> i need the extra 0's at the front to make it 8 bits.

How can i keep them?? or add them in later to an Integer?
18 years ago
Answer is defined at the beginning of the method.

int answer = 0;
18 years ago
Hi,

I'm trying to read binary from a text file into java - I want to read 8 bits and then convert that to a CHAR.

This is my code:



The problem I have is it's reading in as a number.
This is my output:

going to decrypt
value of answer b4 parsing: 0
value of answer: 17
inside decrypt for printb
this is the output: ◄
value of answer b4 parsing: 17
value of answer: 14
inside decrypt for printb
this is the output: ♫


basically I want value of answer b4 parsing to be : 00001111 (as a string)
value of answer: 00001111 (but as a int not a string)
because i pipe that into a decryption algoritm that takes the 8 bits and decrypts then i can convert back to char.

Any help would be much appreciated.
18 years ago
Ahh yep works good now - thanks ..
18 years ago
Hey,

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)

C:\sdes>
18 years ago
Sorry, i'm unsure where you attained buffer from ??
should it be filename instead ? ?
19 years ago
Unfortunately i cannot .. As i'm converting to a hex string the file.length() is too small .. I originally had it as that .. and only approx half of the file would be read into the byte array . .
19 years ago
Hi,
I'm trying to read from a text file into a byte[] array, and then convert that byte array into hex code.
The problem i have is assigning the length of my array. At the moment my code looks as such;
----------------------------------------
FileInputStream fis = new FileInputStream(file);
// R E A D
byte[] ba = new byte[1024];
// -1 means eof
int bytesRead;
bytesRead = fis.read( ba, 0 /* offset in ba */, ba.length /* bytes to read */ );
return ba;
}
-------------------------------------------
i've set my byte to the value of 1024. Which gives me alot of zeros, but i get the right hex input into the start of the array.
i need to make the length only as long as the next greatest power of 64bit (8 bytes). (and pad to complete the fields)
The covered quotient looks as follows
(dividend >= 0) ? ( (dividend + divisor - 1 ) / divisor) : (dividend / divisor );
however i do not know how to implement that ..
Any help would be much appreciated. .
John
19 years ago