1

I want to recover this long value, that was mistakenly converted to int

long longValue = 11816271602;
int intValue = (int)longValue; // gives -1068630286
long ActualLong = ?

Right shift 32 bits of (intValue >> 32) gives incorrect result.

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Kamran Qadir
  • 466
  • 10
  • 20

2 Answers2

5

Well, the initial value

long longValue = 11816271602L; // 0x02C04DFEF2 

is five bytes long. When you cast the value to Int32 which is four bytes long

int intValue = (int)longValue; // 0xC04DFEF2 (note 1st byte 02 absence)

you inevitably lose the 1st byte and can't restore it back.

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
1

Unfortunately this is not possible. If you take a look at the binary representation you can see the reason:

10 1100 0000 0100 1101 1111 1110 1111 0010

As you can see, this number has 34-bit and not only 32-bit.

Oliver
  • 43,366
  • 8
  • 94
  • 151