Using Variables: A Quad-Word |
|
Introduction |
Sometimes you may want to store values that a double-word cannot handle. To store a very large number in a variable, you can consider a combination of 64 bits. The group can also be referred to as a quad-word. A quad-word is so large it can store numbers in the range of –9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.
|
To use a variable that can hold very large numbers that would require up to 64 bits, declare it using the long keyword.
Here is an example that uses the long data type: using System; class NumericRepresentation { static void Main() { long CountryArea; CountryArea = 5638648; Console.Write("Country Area: "); Console.Write(CountryArea); Console.Write("km2\n"); } } This would produce: Country Area: 5638648km2 Although the long data type is used for large number, it mainly indicates the amount of space available but you don't have to use the whole space. For example, you can use the long keyword to declare a variable that would hold the same range of numbers as the short, the int, or the uint data types. If you declare a variable as long but use it for small numbers that don't require 64 bits, the compiler would allocate the appropriate amount of space to accommodate the values of the variable. Consequently, the amount of space made available may not be as large as 64 bits. If you insist and want the compiler to reserve 64 bits, when assigning a value to the variable, add an L suffix to it. Here is an example that uses space of a long data type to store a number that would fit in 32 bits: using System; class NumericRepresentation { static void Main() { long CountryArea; CountryArea = 5638648L; Console.Write("Country Area: "); Console.Write(CountryArea); Console.Write("km2\n"); } } Therefore, keep in mind that an int, a uint, a short, or a ushort can fit in a long variable. You can use a combination of 64 bits to store positive or negative integers. In some cases, you will need a variable to hold only positive, though large, numbers. To declare such a variable, you can use the ulong data type. A variable declared as ulong can handle extremely positive numbers that range from 0 to 18,446,744,073,709,551,615 to fit in 64 bits. |
|
||
Previous | Copyright © 2006-2007 FunctionX, Inc. | Next |
|