Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

long data type overflow 1

Status
Not open for further replies.

dontyell

Programmer
Feb 28, 2003
10
0
0
US
Hi,

I am running into a problem. I was trying to assign the value 128 * 16777216 to a C# long data type. I always got overflow error. I checked the range of the long data type, the overflow shouldn't occur in my case. Anyone has any suggestion?

Thanks,
Cindy
 
Write
Code:
long lv = 128 * (long)16777216 ;
-obislavu-
 
Thanks for the quick response. Actually I tried this and it works! But why should I do this? Isn't it supposed to implicitly convert to long data type?
 
When you write long lv = 128 * 16777216 ; the evaluation is made from right to left, that means first multiply 128 by 16777216 as integer numbers and the result is assigned (and converted) to a long. But the result cannot be calculated due to overflow.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top