This discussion is archived
12 Replies Latest reply: Mar 8, 2008 11:57 PM by 807591 RSS

how to convert long to string

807591 Newbie
Currently Being Moderated
if i give a long value then i should get a string

for instance

long x=11597114117;

then output should be saru(s-115 a -97 r-114 u-117)

any solution for it
  • 1. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    While I have no idea what you're talking about with saru(s-115 a -97 r-114 u-117), Google would tell you your answer:
    http://stuff.mit.edu/people/ele/Javaconversion.htm
  • 2. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    hey,
    dint u understood my query or is that u cannot answer??

    need to know so that i can elaborate


    --?here it goes

    if i enter a string say "saru"then the corresponding long value is 11597114117 (it represents the ascii of each character s-115 a -97 r-114 u-117)

    now if i enter this long value can i be able to get my string back
  • 3. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    saru wrote:
    dint u understood my query or is that u cannot answer??
    Replies like this will certainly not help you get an answer.
    Did you bother to follow the link newark provided? +(the answer you want is there)+
  • 4. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    String str = Long.toString(l);

    i have tried this but its not getting internally parsed

    if the long value is 97 after converting it in to string by using the above method the ouput is 97 only instead of character 'a'
  • 5. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    newark wrote:
    http://stuff.mit.edu/people/ele/Javaconversion.htm
    The answer you want is here.
  • 6. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    There is only one method Long.toString(l);

    i tried it but its not giving ascii value...........

    any other Alternatives......please............
  • 7. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    saru wrote:
    long x=11597114117;
    Where does that long value come from? This is a very unusual and ineffective way to store multiple characters in a long.
  • 8. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    let me ask you this: if you have 115, how did you decide to treat that as one character (115); not two (11, 5) or three (1, 1, 5)?
  • 9. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    If he uses only a-z (97-122), it should be fine. I still don't see any use for such a strange code anyway.
  • 10. Re: how to convert long to string
    baftos Expert
    Currently Being Moderated
    nevermind}

    Edited by: baftos on Mar 8, 2008 2:15 PM
  • 11. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    For the readers who missed his previous topic, here it is: http://forum.java.sun.com/thread.jspa?threadID=5272389

    It is really sad to see how he heavily misunderstood the basic concepts of programming.

    Saru, to get serious help, please elaborate your functional requirements in detail. It is very clear that you're thinking in the completely wrong direction to solve your problem. You won't have much luck if you keep asking others how to use a screwdriver to slam a nail.
  • 12. Re: how to convert long to string
    807591 Newbie
    Currently Being Moderated
    public int rabbit_cipher(Rabbit_Instance p_instance, final String p_src,String p_dest, int data_size)
         {
              /* Temporary variables */
              int i;
              long s0,s1,s2,s3;
              long m0,m1,m2,m3;
              
              String temp=null;     
              /* Return error if the size of the data to encrypt is */
              /* not a multiple of 16 */
              if (data_size%16!=0)
                   return (-1);
              
              JOptionPane.showMessageDialog(null,"in allfunctions");               
              for (i=0; i<data_size; i+=16)
              {
                   /* Iterate the system */
                   rabbit_next_state(p_instance);
                   s0=Convert(p_dest.substring(i,i+4)); /*Convert() here is a user defined function*/
                   s1=Convert(p_dest.substring(i+4,i+8));
                   s2=Convert(p_dest.substring(i+8,i+12));
                   s3=Convert(p_dest.substring(i+12,i+16));
                   
                             
                   m0=Convert(p_src.substring(i,i+4));
                   m1=Convert(p_src.substring(i+4,i+8));
                   m2=Convert(p_src.substring(i+8,i+12));
                   m3=Convert(p_src.substring(i+12,i+16));     
                   
                                  
                   /* Encrypt 16 bytes of data */
                   s0=m0 ^ p_instance.x[0] ^ (p_instance.x[5] >> 16) ^ (p_instance.x[3] << 16);
                   s1=m1^ p_instance.x[2] ^ (p_instance.x[7] >> 16) ^ (p_instance.x[5] << 16);
                   s2=m2 ^ p_instance.x[4] ^ (p_instance.x[1] >> 16) ^ (p_instance.x[7] << 16);
                   s3=m3 ^ p_instance.x[6] ^ (p_instance.x[3] >> 16) ^ (p_instance.x[1] << 16);
    JOptionPane.showMessageDialog(null,"cipher2");
         JOptionPane.showMessageDialog(null,String.valueOf(s0));
                   temp.concat(String.valueOf(s0));
                   temp.concat(String.valueOf(s1));
                   temp.concat(String.valueOf(s2));
                   temp.concat(String.valueOf(s3));
                   
              }
                   JOptionPane.showMessageDialog(null,"cipher");
                                  JOptionPane.showMessageDialog(null,temp);     
                   p_dest=null;
                   p_dest.concat(temp);
              /* Return success */
              return 0;
         }

    }     
         public long Convert(String str)
         {
              char[] chr = str.toCharArray();

              StringBuilder encode = new StringBuilder();

              for(int i=0;i<chr.length;i++)
              encode.append((int)chr);

              return(Long.parseLong(encode.toString()));
         }
         


    now p_dest should contain s0,s1,s2,s3 values concatenated values that are stored in temp