Alex Rivera | Logout

Convert a long to two int for the purpose of reconstruction

Asked 2011-06-02T19:51:14.113
11

I need to pass a parameter as two int parameters to a Telerik Report since it cannot accept Long parameters. What is the easiest way to split a long into two ints and reconstruct it without losing data?

Edit
Report

2 Answers

4

For unigned the following will work:

ulong value = ulong.MaxValue - 12;
uint low = (uint)(value & (ulong)uint.MaxValue);
uint high = (uint)(value >> 32);

ulong value2 = ((ulong)high << 32) | low;
answered 2011-06-02T20:30:10.147
1

Converting it to and from a string would be much simpler than converting it two and from a pair of ints. Is this an option?

string myStringValue = myLongValue.ToString();

myLongValue = long.Parse(myStringValue);
answered 2011-06-02T20:30:23.500

Your Answer