Win a copy of Design for the Mind this week in the Design forum!

# conversion

vijay umar
Ranch Hand
Posts: 100
i wish to change a word like "hello" into a binary format in which each letter represented in binary form ex: hello is 01101000 01100101 01101100 01101100 01101111

and i want to take each group of this binary code and perform Xor function between each of them and then to print it.can any body help me with this logic?

Sebastian Janisch
Ranch Hand
Posts: 1183
What is it you want to achieve with your code ?

vijay umar
Ranch Hand
Posts: 100
its an algorithm called luby transformation codes! it helps in authentication

Rob Spoor
Sheriff
Posts: 20511
54
There are a few steps to this:
- convert the String to characters: either use String.toCharArray() or String.charAt(int) and String.length()
- convert each char into a number. Oh wait, char already is numeric! 't' is the same as (char)104.
- perform xor on each number. The operator is ^.

So in pseudo code:
This will only work for characters that need only one byte, i.e. the ASCII characters (0-127). For others c will be need more than 8 bits to represent itself. You can use a bitwise AND to chop off everything after the first 8 bits: I wrote down 127 here to indicate it is the maximum value of an ASCII character / byte. You will also often see 0x7F (hexadecimal) but that's the same.

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36