-2

Is there a way to convert a long value 8769402740 to integer and still maintain the original value . I know about using (int) long however it changes the appearance of the number and that is what I would like to maintain.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
chloe
  • 69
  • 2
  • 10
  • Using C#, int means Int32, so 32 bits; long number you're giving us uses 33 bits (hex 2 0AB2 7774) so how can you preserve value? What do you mean with *appearance of the number*? – Marco Jan 26 '12 at 14:29
  • Change the base? Logarithms are cool. – SQLMason Feb 13 '12 at 18:11

4 Answers4

3

Using C#, int means Int32, so manages 32 bits numbers.
Long number you're giving us uses 33 bits (hex 20AB27774) so you cannot preserve its value after conversion.
For this reason your number gets truncated within 32 bits and become 0AB27774.

Marco
  • 56,740
  • 14
  • 129
  • 152
2

Considering you're using C# since you did not mention your programming language and platform...

It's not possible.

Int32.MaxValue value is 2,147,483,647. This way you cannot accommodate 8,769,402,740 in an int variable.

See Casting and Type Conversions (C# Programming Guide).

For built-in numeric types, an implicit conversion can be made when the value to be stored can fit into the variable without being truncated or rounded off. For example, a variable of type long (8 byte integer) can store any value that an int (4 bytes on a 32-bit computer) can store. The inverse is not possible without losing data.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
0

You will need tp give more information that this, for example, which language are you trying to do this in, and on what platform??

An integer changes according to the bit length of the processor being used in most cases.

Also can you explain what you mean by maintain appearance?

An integer on a 32-bit version of windows cannot hold the value 8769402740 as it is too large.

Graham
  • 318
  • 1
  • 16
0

You can "compress" a large number to a smaller number, please see the Shannon Limit. However, you'd have to maintain a way to store that data. What you're asking for is either non-trivial or impossible for the reasons given by Marco.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
SQLMason
  • 3,275
  • 1
  • 30
  • 40