Results 1 to 9 of 9
  1. #1
    ganchinyong is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default How can i get 64-bit from a String?

    Hi,

    I want to ask that how can i get 64-bit from a String?
    Eg:
    String ss = "I want to ask that how can i get 64-bit from a String?";

    How can I get 64-bit from ss?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,559
    Rep Power
    23

    Default

    I take it you are talking about Strings not bits.
    If you know the offset of the desired substring, use the substring method.
    To get the offset use the indeOf method

  3. #3
    ganchinyong is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Its 64 bits

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by ganchinyong View Post
    Its 64 bits
    A single char is stored as 16 bits; do you want four consecutive chars as, say, one long?

    kind regards,

    Jos

  5. #5
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    String class uses char array to combine a text line.
    Just do next 64/16=4
    So "text" is 64 bits word ;)
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,448
    Rep Power
    18

    Default

    Re-reading the OP, I think (as Norm does) that they're asking how to get the text "64-bits" from another text string...but I can't actually see the point. In order to get that text, you'd have to use that text to find the index for it, which you'd then use to get...the test...which you already have.

    Unless it's actually a "does this text exist in this String" question, in which case a simple indexOf would do the trick.

    All in all, not the best worded question we've had...so can you clarify please?

  7. #7
    ganchinyong is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Lets say there is a string "Hello world"
    I wish to split the string above to 64-bits each.
    And the result that I want is in bit.

    Maybe the following will helps:
    Use getBytes function, and then combine each group of 8 using left shifts and the bitwise or operator.
    Can one provide with the sample coding? Cause I'm new to Java =(
    Thanks

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,448
    Rep Power
    18

    Default

    Ah, so Norm and I got the question wrong...:)

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Have a look at the ByteBuffer class: given you byte[] wrap it in a ByteBuffer and get a long out of it.

    kind regards,

    Jos

Similar Threads

  1. Replies: 7
    Last Post: 11-03-2009, 02:18 AM
  2. combine string[] into string like perl's join function
    By tekberg in forum Advanced Java
    Replies: 9
    Last Post: 02-23-2009, 01:05 PM
  3. Replies: 5
    Last Post: 01-11-2009, 10:12 AM
  4. Replies: 0
    Last Post: 11-20-2007, 04:59 PM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •