473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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..
Mar 21 '10 #1
3 2712
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.toString(l1);
String s2=Long.toString(l2);

String s=s1+s2;

long l=Long.valueOf(s).LongValue();
Mar 21 '10 #2
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
Mar 22 '10 #3
jkmyoung
2,057 Expert 2GB
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.
Mar 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kevin King | last post by:
I have a question about an assignment I have. I need to count the number of comparisons in my merge sort. I know that the function is roughly nlog(n), but I am definately coming up with too many...
12
by: jose luis fernandez diaz | last post by:
Hi, My OS is: cronos:jdiaz:tmp>uname -a HP-UX cronos B.11.11 U 9000/800 820960681 unlimited-user license I compile in 64-bits mode the program below:
7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
0
by: beerman | last post by:
I have developed an app (in Access 2002) that dynamically creates a table, and the fields in that table, for propagation based on the max number of occurences in a reference table. Basically, it...
6
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but...
7
by: Defected | last post by:
Thanks all for help, I have tried this code but it's don't work. -------------------------------------------------------------------- Structure typedef struct{ int atomic_number; char...
1
by: barny | last post by:
Hi all, I have been trying to merge two access tables together all morning with no succsess. In table one I have Account Number|Return1|Return2|Return3| M1234567 | P9832 | Q1234 | P4322 |...
2
by: mqueene7 | last post by:
below is my code for my merge sort but I can't get it to sort properly. I am trying generate random numbers based on input from the user and then sort those random numbers. Can you tell me what I...
17
by: Tarique | last post by:
This program was compiled on MS Visual C++ 08 /*Fibonacci Numbers*/ #include<stdio.h> #include<limits.h> void fibonacci(int n) { unsigned long long fib0 = 0; /*First Fibonacci Number*/
8
by: Mark Main | last post by:
I just bought Visual Studio 2008, I'm new to C# and trying to learn it. I'm stuck and would appreciate some help. I need to make the fastest code I can to work with a large key (it's 200 bytes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.