merge two long numbers into one long number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jatinch
    New Member
    • Mar 2010
    • 7

    merge two long numbers into one long number

    i am implementing blowfish algorithm..
    i have a long number or a 64 bit no. say X
    i have to divide this 64 bit block into two 32 bit blocks say xl and xr.

    after doing some calculations i have to convert these two 32 bit blocks into 64 bit block again..
    so how do i do this


    pls help..
  • anurag275125
    New Member
    • Aug 2009
    • 79

    #2
    Convert two long numbers into String, then merge these two strings and then again convert this string into long number like this:

    long l1=1234
    long l2=5678

    String s1=Long.toStrin g(l1);
    String s2=Long.toStrin g(l2);

    String s=s1+s2;

    long l=Long.valueOf( s).LongValue();

    Comment

    • jatinch
      New Member
      • Mar 2010
      • 7

      #3
      hii
      thanks for the reply
      but the problem i am facing now is that it is giving me number format exception for string s
      i guess the string becomes too large to be stored in a long no.
      what i want is
      a long no. X ( 64 bit )
      divide to two 32 bits xl and xr
      and then merge xl and xr as 64 bit X again

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        oh no!
        With the string method, each number won't fill the 32 bit space they have been assigned.
        ulong ul1 = 1234;
        ulong ul2 = 5678;

        ulong result = (ul1 << 32) | ul2;
        Use a bit shift operator instead.

        Comment

        Working...