JY2k
JY2k

Reputation: 2909

Reading ascii file to binary

I've created a file.txt with the string "7F" in it. I read it using apaches library:

byte[] byteArray = IOUtils.toByteArray(new Base64InputStream(new java.io.FileInputStream(fileName)));

And this is the array I get:

[-20]

which equates to 1110 1100 when i was expecting 1111 1111 I guess my question is how to encode a string in ascii which would generate the Byte 1111 1111?

Upvotes: 0

Views: 127

Answers (2)

owaism
owaism

Reputation: 1188

You will have to use the ASCII Character:'ÿ'

The following code should get you what you want:

Character s= 'ÿ';
System.out.println(Integer.toBinaryString(s));

You can use an online utility like: https://www.branah.com/ascii-converter to help you out.

Upvotes: 1

djs
djs

Reputation: 1690

1111 1111 binary = 255 decimal. According to this ASCII chart, that would be the ÿ character.

Upvotes: 1

Related Questions