Results 1 to 6 of 6

Thread: Convert string to binary in java

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Convert string to binary in java

    Hello,
    I need your help I'm doing some algorithm (cipher "cryptography"). During my work I encounter a small problem. Following the principle of IDEA I need to convert my secret key (must be 128 bits == 8 characters) into binary for the shift of 25 positions to the left, but I do not know the method that performs it. I find in the course of my research that the method parseInt () converts the string int, it can convert only 8 bits == 1characters and I find a method parseInt (String, 27) and I have not understood why 27 because it allows me to convert 4characters. How exactly a string is converted to binary in java. Can you help me and i will great for me. Thanks in advance.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Convert string to binary in java

    Hi,
    During my work I encounter a small problem. Following the principle of IDEA I need to convert my secret key (must be 128 bits == 8 characters) into binary for the shift of 25 positions to the left, but I do not know the method that performs it.
    You can do this by
    byte[] b = ex.getBytes();
    I find a method parseInt (String, 27) and I have not understood why 27 because it allows me to convert 4characters.
    It is used to convert a string into a number in base 27.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: Convert string to binary in java

    Hello,
    byte[] b = ex.getBytes();
    I doubt that it works. The characters in Java and therefore the string is in unicode (16 bit), it does not provide 128 bit late but 256.
    byte [] b = ex.getBytes ( "UTF-8");
    should work better.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Convert string to binary in java

    Hello,
    I doubt that it works. The characters in Java and therefore the string is in unicode (16 bit), it does not provide 128 bit late but 256.
    byte [] b = ex.getBytes ( "UTF-8");
    I never said that it should return a number of bytes equal to the number of characters in the string (it depends on the charset of the machine as indicated in the doc). Anyway, your solution is better, I agree with this. But this is true that both the methods will work here. I accept that the method shown is more reliable.

  5. #5
    Join Date
    Dec 2009
    Posts
    263

    Re: Convert string to binary in java

    Hello,
    Thank you, but the result of this function does not return to me a sequence of binary numbers (110110 ...) I'll give you an example to better understand: exString = 'forum development "; my result should be = 001011011 ... (which should not be a string but a binary number). Thank you in advance. I think now you have understood what I am asking for.

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Convert string to binary in java

    Hello,
    The problem here is that your string necessarily becomes a table where each row contains one byte. And now you need to apply the offset to the left of 25 on all those bytes that represent your chain? Or you can do on each byte separately? But what are you going to do with the bits, the bytes are the low level data, I think they are more than enough.

Similar Threads

  1. Problem to convert binary to string
    By steg in forum Software Development
    Replies: 1
    Last Post: 08-04-2011, 01:21 AM
  2. How to convert InputStream to String in java?
    By KALIDA in forum Software Development
    Replies: 4
    Last Post: 20-01-2010, 06:16 PM
  3. How to convert string into int in Java
    By Zool in forum Software Development
    Replies: 3
    Last Post: 09-11-2009, 12:41 PM
  4. Convert binary to decimal in java
    By Seraphim in forum Software Development
    Replies: 2
    Last Post: 20-05-2009, 09:19 AM
  5. Convert Integer to a String in Binary Notation
    By Naval in forum Software Development
    Replies: 2
    Last Post: 16-03-2009, 09:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,643,127.44280 seconds with 17 queries