I am currently working on a Vernam cipher program, and a big part of that is the ability to convert plaintext into binary. I looked into how to do this, and I found that Integer.toBinaryString()
would work best in converting each individual character of the plaintext to binary. For most characters, this conversion works, however, I have found instances that cause me to run into an error in the conversion.
For example, whenever I run this code: System.out.println(Integer.toBinaryString('€'));
I would expect an output of 10000000
, however, I get 10000010101100
outputted instead. According to this ASCII Table, I know extended ASCII characters can have some variation on values, however, most of the characters in this table are accurate in the extended ASCII character section, the Euro is represented by 128 in ASCII.
Why is Integer.toBinaryString('€')
returning 10000010101100
? Is there a way I can fix this?
System.out.println((int)'€')
prints8364