Hoang Tran
Hoang Tran

Reputation: 966

Is there anyway to convert long to int?

Maybe this is a stupid question: I have accidentally cast long value to int value in the database (~ 1M rows), so is there any way to revert it back using code (without restoring the database)? Thanks

Example: My long value: 636705792000000000

Int value after cast: 1587019776

==> Is there any way to find 636705792000000000 when I have only int value (1587019776)

Upvotes: 3

Views: 1623

Answers (1)

DavidG
DavidG

Reputation: 118937

No, you have effectively blanked out half of your data I'm afraid. If you convert those numbers to binary, it may be more obvious:

636705792000000000 => ‭100011010110000010001000101101011110100110000000000000000000‬
        1587019776 =>                             ‭01011110100110000000000000000000‬

Note how the right hand half of the long is the same as the entirety of the int. However, you have completely lost the left half.

Upvotes: 7

Related Questions