468,457 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

splitting u_int64_t into 2 u_int32_t in c++

Hi,

I have a c++ code in which i have combined 2 u_int32_t data into a single u_int64_t data initially.
Now, i need to split this u_int64_t data into their 2 corresponding u_int_32_t data?(I need to gather the values of the 2 u_int32_t as they were before the combination to that u_int64_t).

Can anyone provide me with a piece of code which would help to do this?

Thanking you,
Am_Rich...!
Nov 26 '07 #1
7 4952
gpraghuram
1,275 Expert 1GB
Hi,

I have a c++ code in which i have combined 2 u_int32_t data into a single u_int64_t data initially.
Now, i need to split this u_int64_t data into their 2 corresponding u_int_32_t data?(I need to gather the values of the 2 u_int32_t as they were before the combination to that u_int64_t).

Can anyone provide me with a piece of code which would help to do this?

Thanking you,
Am_Rich...!

What logic you have followed to combine 2 32 bit values to a 64 bit value?
You have to do the reverse.
The logic is usually while combining you will do a OR operation and while separating you have to use AND operation.


Raghuram
Nov 26 '07 #2
Hi Raghuram,
Thanks a lot for your response.
This is in fact the piece of code which ive been using for the combination purpose:

swap_64(u_int32_t x, u_int32_t y)
{
u_int64_t int64a = x;
u_int64_t int64b = y;
return(int64a<<32)|(int64b);

}
Nov 26 '07 #3
Sorry for the improper formatting Raghuram,
I had been accidentally hitting on the Tab Key for some formatting and this has as such resulted to the submission of the post:(

Appology for the inconvenience caused,
Am_Rich...!
Nov 26 '07 #4
gpraghuram
1,275 Expert 1GB
Sorry for the improper formatting Raghuram,
I had been accidentally hitting on the Tab Key for some formatting and this has as such resulted to the submission of the post:(

Appology for the inconvenience caused,
Am_Rich...!
The cobining part is OK but for the splitting part i am not able to get a solution....i need some time...
In the Mean time other members please take a look into this

Raghuram
Nov 27 '07 #5
gpraghuram
1,275 Expert 1GB
The cobining part is OK but for the splitting part i am not able to get a solution....i need some time...
In the Mean time other members please take a look into this

Raghuram
Hi,
I got the idea about how to do that.
Following is the code snippet
Expand|Select|Wrap|Line Numbers
  1. void separateVar(unsigned long long _ip,unsigned long &_var1,unsigned long &_var2)
  2. {
  3.     unsigned long long mask=0x00000000FFFFFFFF;
  4.     _var2=_ip&mask;
  5.     _var1=_ip>>32;
  6. }
  7.  
_ip is the combined variable
_var1 and _var2 is passed as reference.

Thanks
Raghuram
Nov 27 '07 #6
Thanks Raghuram,

Will try implement this.

Regards,
Am_Rich...!
Nov 27 '07 #7
Hi Raghuram,

Its Working!!!
Thanks a lot!!!:)

Regards,
Am_Rich...![/quote]
Nov 27 '07 #8

Post your reply

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

Similar topics

3 posts views Thread by somaBoy MX | last post: by
7 posts views Thread by qwweeeit | last post: by
6 posts views Thread by nwheavyw8 | last post: by
6 posts views Thread by Earl Anderson | last post: by
5 posts views Thread by The Dark Free Soul | last post: by
2 posts views Thread by shadow_ | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.