A Double-Word

Introduction

A double-word is a group of two consecutive Words. This means that a double-word combines 4 bytes or 32 bits. The bits, counted from right to left, start at 0 and end at 31. The most right bit, bit 0, is called the low order bit or LO bit or LOBIT. The most left bit, bit 31, is called the high order bit or HI bit or HIBIT. The other bits are called using their positions.

The group of the first 8 bits (from bit 0 to bit 7), which is the right byte, is called the low order byte, or LOBYTE. The group of the last 8 bits (from bit 24 to bit 31), which is the left byte, is called the high order byte, or HIBYTE. The other bytes are called by their positions. The group of the right 16 bits, or the right Word, is called the low order word, or LOWORD. The group of the left 16 bits, or the left word, is called the high order word, or HIWORD.

The minimum binary number you can represent with a double-word is 0. The minimum decimal value of a double-word is 0. To find out the maximum decimal value of a word, you can use the base 2 formula giving a 1 value to each bit:

 2n-1 230 229 228 227 226 225 224 etc 1,073,741,824 536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216

 223 222 221 220 219 218 217 216 8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536

 215 214 213 212 211 210 29 28 32,768 16,384 8,192 4,096 2,048 1,024 512 256

 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1

1*231+1*230+1*229 + 1*228 + 1*227 + 1*226 + 1*225 + 1*224 + 1*223 + 1*222 + 1*221 + 1*220 + 1*219 + 1*218 + 1*217 + 1*216 + 1*215 + 1*214 + 1*213 + 1*212 + 1*211 + 1*210 + 1*29 + 1*28 + 1*27 + 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20

= 2,147,483,648 + 1,073,741,824 + 536,870,912 + 268,435,456 + 134,217,728 + 67,108,864 + 33,554,432 + 16,777,216 + 8,388,608 + 4,194,304 + 2,097,152 + 1,048,576 + 524,288 + 262,144 + 131,072 + 65,536 + 32,768 + 16,384 + 8,192 + 4,096 + 2,048 + 1,024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1

= 4,286,578,708

The minimum hexadecimal value you can store in a double-word is 0x00000000000000000000000000000000 which is the same as 0x0. To find out the maximum hexadecimal number you can represent with a word, replace every group of 4-bits with an f or F:

 1111 1111 1111 1111 1111 1111 1111 1111 f f f f f f f f = 0xffffffff = 0xFFFFFFFF

To declare a variable that can hold large values, you can use the var keyword and initialize the variable with the desired value. Here is an example:

```using static System.Console;

public class Exercise
{
public static void Main()
{
var apartNbr = 24;

WriteLine("Apartment Rental Management");
Write("Apartment #: ");
WriteLine(apartNbr);
}
}```

This would produce:

```Apartment Rental Management
Apartment #: 24
Press any key to continue . . .```

Practical Learning: Using Unsigned Integers

1. Start Microsoft Visual Studio
2. To create a new application, on the main menu, click File -> New -> Project...
3. In the middle list, click Console App (.NET Framework)
4. Change the Name to CountriesStatistics4
5. Click OK
6. In the Solution Explorer, right-click CountriesStatistics4 -> Add -> Class...
7. Type Region as the Name of the class
9. Change the document as follows:
```namespace CountriesStatistics4
{
public class Region
{
public string Designation { get; set; }
public string Description { get; set; }
}
}```
10. In the Solution Explorer, right-click CountriesStatistics4 -> Add -> New Item...
11. In the left frame of the Add New Item dialog box, click Code and, in the middle frame, click Interface
12. Change the Name to Abbreviated
14. Create a string-based property as follows:
```namespace CountriesStatistics4
{
interface IAbbreviated
{
string Abbreviation { get; set; }
}
}
```

Signed Integers

A double-word is large enough to contain double the amount of data that can be stored in a word. This is equivalent to 32 bits or 4 bytes or 4,294,967,295. Therefore, a double-word is used for small or large numbers.

To use a variable that would hold quite large numbers, besides the var keyword, you can declare it using the int keyword. A variable declared as int can store values between -2,147,483,648 and 2,147,484,647 negative or positive, that can fit in 32 bits.

To let you display an integer to the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes an int argument. Their syntaxes are:

```public static void Write(int value);
public static void WriteLine(int value);```

Here are examples:

```using static System.Console;

public class Exercise
{
public static void Main()
{
int coordX;
int coordY;

coordX = 12;
coordY = -8;

Write("Cartesian Coordinate System: ");
Write("P(");
Write(coordX);
Write(", ");
Write(coordY);
WriteLine(")\n");
}
}```

When executed, the program would produce:

`Cartesian Coordinate System: P(12, -8)`

If the number is large, don't use the character for thousands separators, which in English is the comma used in the English language. Here is an example:

```using static System.Console;

public class Exercise
{
static int Main()
{
int yearlySalary = 82460;

WriteLine("Fun Department Store");
Write("Yearly Salary: ");
WriteLine(yearlySalary);

return 0;
}
}```

The program would produce:

```Fun Department Store
Yearly Salary: 82460
Press any key to continue . . .```

As an alternative, separate the thousands from right to left with underscores. Here are examples:

```using static System.Console;

public class Exercise
{
static int Main()
{
var emplNbr = 20_931_705;
int yearlySalary = 82_460;

WriteLine("Fun Department Store");
Write("Employee #: ");
WriteLine(emplNbr);
Write("Yearly Salary: ");
WriteLine(yearlySalary);

return 0;
}
}```

If you declare an integer variable using the var keyword and initialize it with a value lower than 2,147,484,647, the compiler concludes that the memory needed to store that variable is 32 bits:

When initializing an integral variable, instead of a decimal number, you can also initialize it with a hexadecimal value whose decimal equivalent is less than 2,147,484,647. Here is an example:

```using static System.Console;

public class Exercise
{
static void Main()
{
var number = 0xF0488EA;

Write("Number: ");
WriteLine(number);
}
}```

This would produce:

```Number: 251955434
Press any key to continue . . .```

Unsigned Integers

If the variable must hold only positive natural numbers, you can declare it using the uint keyword, which represents an unsigned integer. The uint keyword is used to identify a 32-bit positive integer whose value would range from 0 to 4,294,967,295.

To let you display an unsigned integer to the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a uint argument. Their syntaxes are:

```public static void Write(uint value);
public static void WriteLine(uint value);```

Here are examples:

```using static System.Console;

public class Exercise
{
static void Main()
{
uint dayOfBirth;
uint monthOfBirth;
uint yearOfBirth;

dayOfBirth   = 8;
monthOfBirth = 11;
yearOfBirth  = 1996;

WriteLine("Red Oak High School");
Write("Student Date of Birth: ");
Write(monthOfBirth);
Write("/");
Write(dayOfBirth);
Write("/");
Write(yearOfBirth);
}
}```

This would produce:

```Red Oak High School
Student Date of Birth: 11/8/1996```

Once again, if the number is large, you can use the underscore to separater the thousands.

Practical Learning: Using Unsigned Integers

1. In the Solution Explorer, right-click CountriesStatistics4 -> Add -> New Item
2. In the middle list of the dialog box, make sure Interface is selectd. Change the Name to GovernmentEntity
4. Change the class as follows:
```namespace CountriesStatistics4
{
interface IGovernmentEntity
{
string Name    { get; set; }
uint    Area    { get;      }
string Capital { get; set; }
}
}```
5. In the Solution Explorer, right-click CountriesStatistics4 -> Add -> Class...
6. Type State as the name of the file
7. Press Enter
8. Change the class as follows:
```using System;

namespace CountriesStatistics4
{
public class State : IAbbreviated,
IGovernmentEntity,
IComparable
{
// From the IAbbreviated interface
public string Abbreviation { get; set; }
// From the IGovernmentEntity interface
public string Name    { get; set; }
public uint Area       { get; set; }
public string Capital { get; set; }

// New Properties
public string StateName => Name;
public uint AreaSqrMiles => Area;
public uint AreaSqrKms   { get; set; }
public Region Region    { get; set; }

public int CompareTo(object stt)
{
if (stt == null)
{
return 0;
}

State other = stt as State;

if (other != null)
return StateName.CompareTo(other.StateName);

return 0;
}
}
}```
9. In the Solution Explorer, right-click CountriesStatistics4 -> Add -> Class...
10. Type Federation
12. Change the class as follows:
```namespace CountriesStatistics4
{
public class Federation : State
{
public ushort AdmissionUnionOrder { get; set; }
}
}```
13. In the Solution Explorer, right-click Program.cs and click Rename
14. Type CountriesStatistics to get CountriesStatistics.cs
15. Read the message box and click Yes
16. In the Solution Explorer, double-click CountriesStatistics.cs to access it
17. To use unsigned variables, change the file as follows:
```using System;

namespace CountriesStatistics4
{
public class CountriesStatistics
{
private static void Display(Array entities)
{
Console.Clear();

Console.WriteLine("                                 United States of America");
Console.WriteLine("=========================================================================================================");
Console.WriteLine(" # Abbrv State Name        SqrMls     Km2        to Union            Capital         Region");
Console.WriteLine("---------------------------------------------------------------------------------------------------------");

for (int counter = 0; counter <= entities.Length - 1; counter++)
{
Federation stt = (Federation)entities.GetValue(counter);

Console.WriteLine("{0,2}  {1,2}   {2}   {3,6}   {4,7}    {5,8}               {6}  {7}",
counter + 1, stt.Abbreviation, stt.StateName,
stt.AreaSqrMiles, stt.AreaSqrKms,
}
Console.WriteLine("=========================================================================================================");
}

public static int Main(string[] args)
{
Region[] regions = new Region[]
{
new Region() { Designation = "East North Central", Description = "The East North Central region includes the states around the Great Lakes." },
new Region() { Designation = "East South Central", Description = "The East South Central portion is one of the regions designated as the South." },
new Region() { Designation = "New England       ", Description = "New England is the group of states in the North-East region. It is delimited in the North and North-East by Canada, in the East by the Atlantic Ocean, and in the South and West by the New York state." },
new Region() { Designation = "Mid-Atlantic      ", Description = "Mid-Atlantic is a region situated in the south of New England. Mid-Atlantic is one of the regions defined by the Census bureau for statistical purposes." },
new Region() { Designation = "Mountain          ", Description = "Like the name suggests, the Mountain region covers states known for their mountaneous characteristics. They are also covered by desertic areas." },
new Region() { Designation = "Pacific           ", Description = "The Pacific region covers the costal western states plus the two non-continental states of Alaska and the Hawaiian islands. All states in this region have a coast on the Pacific Ocean." },
new Region() { Designation = "South Atlantic    ", Description = "The South Atlantic region includes the states in the South-East part but also counts the Disctrict of Columbia." },
new Region() { Designation = "West North Central", Description = "The West North Central region includes the states in the Great Planes area. This reqion is divided from the East North Central part by the Mississippi River. This region is characterized by vast agricultural farms and high employment." },
new Region() { Designation = "West South Central", Description = "The West South Central part is one of the regions with (only) four states. The imposing Texas state is both the largest and the most populous state in the region." }
};

Federation[] states = new Federation[40];

states[0]  = new Federation() { Abbreviation = "RI", Name = "Rhode Island  ", Area =    1545, AreaSqrKms =      4002, AdmissionUnionOrder = 13, Capital = "Providence    ", Region = regions[2] };
states[1]  = new Federation() { Abbreviation = "OH", Name = "Ohio          ", Area =  44_828, AreaSqrKms =   116_103, AdmissionUnionOrder = 17, Capital = "Columbus      ", Region = regions[0] };
states[2]  = new Federation() { Abbreviation = "KY", Name = "Kentucky      ", Area =  40_411, AreaSqrKms =   104_665, AdmissionUnionOrder = 15, Capital = "Frankfort     ", Region = regions[2] };
states[3]  = new Federation() { Abbreviation = "IA", Name = "Iowa          ", Area =  56_276, AreaSqrKms =   145_754, AdmissionUnionOrder = 29, Capital = "Des Moines    ", Region = regions[7] };
states[4]  = new Federation() { Abbreviation = "WI", Name = "Wisconsin     ", Area =  65_503, AreaSqrKms =   169_653, AdmissionUnionOrder = 30, Capital = "Madison       ", Region = regions[0] };
states[5]  = new Federation() { Abbreviation = "VT", Name = "Vermont       ", Area =    9615, AreaSqrKms =    24_903, AdmissionUnionOrder = 14, Capital = "Montpelier    ", Region = regions[2] };
states[6]  = new Federation() { Abbreviation = "ID", Name = "Idaho         ", Area =  83_574, AreaSqrKms =   216_456, AdmissionUnionOrder = 43, Capital = "Boise         ", Region = regions[4] };
states[7]  = new Federation() { Abbreviation = "ME", Name = "Maine         ", Area =  35_387, AreaSqrKms =    91_653, AdmissionUnionOrder = 23, Capital = "Augusta       ", Region = regions[2] };
states[8]  = new Federation() { Abbreviation = "OR", Name = "Oregon        ", Area =  98_386, AreaSqrKms =   254_819, AdmissionUnionOrder = 33, Capital = "Salem         ", Region = regions[5] };
states[9]  = new Federation() { Abbreviation = "ND", Name = "North Dakota  ", Area =  70_704, AreaSqrKms =   183_123, AdmissionUnionOrder = 39, Capital = "Bismarck      ", Region = regions[7] };
states[10] = new Federation() { Abbreviation = "IN", Name = "Indiana       ", Area =  36_420, AreaSqrKms =    94_328, AdmissionUnionOrder = 19, Capital = "Indianapolis  ", Region = regions[0] };
states[11] = new Federation() { Abbreviation = "MS", Name = "Mississippi   ", Area =  48_434, AreaSqrKms =   125_443, AdmissionUnionOrder = 20, Capital = "Jackson       ", Region = regions[1] };
states[12] = new Federation() { Abbreviation = "TX", Name = "Texas         ", Area = 268_601, AreaSqrKms =   695_676, AdmissionUnionOrder = 28, Capital = "Austin        ", Region = regions[8] };
states[13] = new Federation() { Abbreviation = "MT", Name = "Montana       ", Area = 147_046, AreaSqrKms =   380_850, AdmissionUnionOrder = 41, Capital = "Helena        ", Region = regions[4] };
states[14] = new Federation() { Abbreviation = "NC", Name = "North Carolina", Area =  53_821, AreaSqrKms =   139_397, AdmissionUnionOrder = 12, Capital = "Raleigh       ", Region = regions[6] };
states[15] = new Federation() { Abbreviation = "TN", Name = "Tennessee     ", Area =  42_146, AreaSqrKms =   109_158, AdmissionUnionOrder = 16, Capital = "Nashville     ", Region = regions[1] };
states[16] = new Federation() { Abbreviation = "NE", Name = "Nebraska      ", Area =  77_358, AreaSqrKms =   200_358, AdmissionUnionOrder = 37, Capital = "Lincoln       ", Region = regions[7] };
states[17] = new Federation() { Abbreviation = "IL", Name = "Illinois      ", Area =  57_918, AreaSqrKms =   150_007, AdmissionUnionOrder = 21, Capital = "Springfield   ", Region = regions[0] };
states[18] = new Federation() { Abbreviation = "KS", Name = "Kansas        ", Area =  82_282, AreaSqrKms =   213_110, AdmissionUnionOrder = 34, Capital = "Topeka        ", Region = regions[7] };
states[19] = new Federation() { Abbreviation = "NH", Name = "New Hampshire ", Area =    9351, AreaSqrKms =    24_219, AdmissionUnionOrder =  9, Capital = "Concord       ", Region = regions[2] };
states[20] = new Federation() { Abbreviation = "DE", Name = "Delaware      ", Area =    2489, AreaSqrKms =      6447, AdmissionUnionOrder =  1, Capital = "Dover         ", Region = regions[6] };
states[21] = new Federation() { Abbreviation = "NJ", Name = "New Jersey    ", Area =    8722, AreaSqrKms =    22_590, AdmissionUnionOrder =  3, Capital = "Trenton       ", Region = regions[3] };
states[22] = new Federation() { Abbreviation = "AK", Name = "Alaska        ", Area = 656_424, AreaSqrKms = 1_700_139, AdmissionUnionOrder = 49, Capital = "Juneau        ", Region = regions[5] };
states[23] = new Federation() { Abbreviation = "NM", Name = "New Mexico    ", Area = 121_598, AreaSqrKms =   314_939, AdmissionUnionOrder = 47, Capital = "Santa Fe      ", Region = regions[4] };
states[24] = new Federation() { Abbreviation = "NY", Name = "New York      ", Area =  54_475, AreaSqrKms =   141_089, AdmissionUnionOrder = 11, Capital = "Albany        ", Region = regions[3] };
states[25] = new Federation() { Abbreviation = "CA", Name = "California    ", Area = 163_707, AreaSqrKms =   424_002, AdmissionUnionOrder = 31, Capital = "Sacramento    ", Region = regions[5] };
states[26] = new Federation() { Abbreviation = "MO", Name = "Missouri      ", Area =  69_709, AreaSqrKms =   180_546, AdmissionUnionOrder = 24, Capital = "Jefferson City", Region = regions[7] };
states[27] = new Federation() { Abbreviation = "OK", Name = "Oklahoma      ", Area =  69_903, AreaSqrKms =   181_049, AdmissionUnionOrder = 46, Capital = "Oklahoma City ", Region = regions[8] };
states[28] = new Federation() { Abbreviation = "PA", Name = "Pennsylvania  ", Area =  46_058, AreaSqrKms =   119_291, AdmissionUnionOrder =  2, Capital = "Harrisburg    ", Region = regions[3] };
states[29] = new Federation() { Abbreviation = "SC", Name = "South Carolina", Area =  32_007, AreaSqrKms =    82_898, AdmissionUnionOrder =  8, Capital = "Columbia      ", Region = regions[6] };
states[30] = new Federation() { Abbreviation = "WY", Name = "Wyoming       ", Area =  97_818, AreaSqrKms =   253_349, AdmissionUnionOrder = 44, Capital = "Cheyenne      ", Region = regions[4] };
states[31] = new Federation() { Abbreviation = "SD", Name = "South Dakota  ", Area =  77_122, AreaSqrKms =   199_745, AdmissionUnionOrder = 40, Capital = "Pierre        ", Region = regions[7] };
states[32] = new Federation() { Abbreviation = "UT", Name = "Utah          ", Area =  84_904, AreaSqrKms =   219_902, AdmissionUnionOrder = 45, Capital = "Salt Lake City", Region = regions[4] };
states[33] = new Federation() { Abbreviation = "AL", Name = "Alabama       ", Area =  52_423, AreaSqrKms =   135_775, AdmissionUnionOrder = 22, Capital = "Montgomery    ", Region = regions[1] };
states[34] = new Federation() { Abbreviation = "VT", Name = "Vermont       ", Area =    9615, AreaSqrKms =    24_903, AdmissionUnionOrder = 14, Capital = "Montpelier    ", Region = regions[2] };
states[35] = new Federation() { Abbreviation = "AR", Name = "Arkansas      ", Area =  53_182, AreaSqrKms =   137_742, AdmissionUnionOrder = 25, Capital = "Little Rock   ", Region = regions[8] };
states[36] = new Federation() { Abbreviation = "WA", Name = "Washington    ", Area =  71_303, AreaSqrKms =   184_674, AdmissionUnionOrder = 42, Capital = "Olympia       ", Region = regions[5] };
states[37] = new Federation() { Abbreviation = "AZ", Name = "Arizona       ", Area = 114_006, AreaSqrKms =   295_276, AdmissionUnionOrder = 48, Capital = "Phoenix       ", Region = regions[4] };
states[38] = new Federation() { Abbreviation = "WV", Name = "West Virginia ", Area =  24_231, AreaSqrKms =    62_759, AdmissionUnionOrder = 35, Capital = "Charleston    ", Region = regions[6] };
states[39] = new Federation() { Abbreviation = "LA", Name = "Louisiana     ", Area =  51_844, AreaSqrKms =   134_275, AdmissionUnionOrder = 18, Capital = "Baton Rouge   ", Region = regions[8] };

Array.Resize(ref states, states.Length + 5);

states[40] = new Federation() { Abbreviation = "MA", Name = "Massachusetts ", Area =  10_555, AreaSqrKms =    27_337, AdmissionUnionOrder =  6, Capital = "Boston        ", Region = regions[2] };
states[41] = new Federation() { Abbreviation = "FL", Name = "Florida       ", Area =  65_758, AreaSqrKms =   170_313, AdmissionUnionOrder = 27, Capital = "Tallahassee   ", Region = regions[6] };
states[42] = new Federation() { Abbreviation = "GA", Name = "Georgia       ", Area =  59_441, AreaSqrKms =   153_953, AdmissionUnionOrder =  4, Capital = "Atlanta       ", Region = regions[6] };
states[43] = new Federation() { Abbreviation = "HI", Name = "Hawaii        ", Area =  10_932, AreaSqrKms =    28_313, AdmissionUnionOrder = 50, Capital = "Honolulu      ", Region = regions[5] };
states[44] = new Federation() { Abbreviation = "MD", Name = "Maryland      ", Area =  12_407, AreaSqrKms =    32_135, AdmissionUnionOrder =  7, Capital = "Annapolis     ", Region = regions[6] };

Federation[] temporary = new Federation[states.Length + 5];

Array.Copy(states, temporary, states.Length);

states = temporary;

states[45] = new Federation() { Abbreviation = "CO", Name = "Colorado      ", Area = 104_100, AreaSqrKms = 269_620, AdmissionUnionOrder = 38, Capital = "Denver        ", Region = regions[4] };
states[46] = new Federation() { Abbreviation = "MI", Name = "Michigan      ", Area =  98_810, AreaSqrKms = 250_738, AdmissionUnionOrder = 26, Capital = "Lansing       ", Region = regions[0] };
states[47] = new Federation() { Abbreviation = "MN", Name = "Minnesota     ", Area =  86_943, AreaSqrKms = 225_182, AdmissionUnionOrder = 32, Capital = "Saint Paul    ", Region = regions[7] };
states[48] = new Federation() { Abbreviation = "CT", Name = "Connecticut   ", Area =    5544, AreaSqrKms =  14_358, AdmissionUnionOrder =  5, Capital = "Hartford      ", Region = regions[3] };
states[49] = new Federation() { Abbreviation = "NV", Name = "Nevada        ", Area = 110_567, AreaSqrKms = 286_368, AdmissionUnionOrder = 36, Capital = "Frankfort     ", Region = regions[4] };

Display(states);

Console.Write("Do you want to sort the list in alphabetical order (y/n)? ");

{
Array.Sort(states);
Display(states);
}
else
{
Console.WriteLine("Good Bye!!!");
Console.WriteLine("====================================================================================================");
}

return 0;
}
}
}```
```                                 United States of America
=========================================================================================================
# Abbrv State Name        SqrMls     Km2        to Union            Capital         Region
---------------------------------------------------------------------------------------------------------
1  RI   Rhode Island       1545      4002          13               Providence      New England
2  OH   Ohio              44828    116103          17               Columbus        East North Central
3  KY   Kentucky          40411    104665          15               Frankfort       New England
4  IA   Iowa              56276    145754          29               Des Moines      West North Central
5  WI   Wisconsin         65503    169653          30               Madison         East North Central
6  VT   Vermont            9615     24903          14               Montpelier      New England
7  ID   Idaho             83574    216456          43               Boise           Mountain
8  ME   Maine             35387     91653          23               Augusta         New England
9  OR   Oregon            98386    254819          33               Salem           Pacific
10  ND   North Dakota      70704    183123          39               Bismarck        West North Central
11  IN   Indiana           36420     94328          19               Indianapolis    East North Central
12  MS   Mississippi       48434    125443          20               Jackson         East South Central
13  TX   Texas            268601    695676          28               Austin          West South Central
14  MT   Montana          147046    380850          41               Helena          Mountain
15  NC   North Carolina    53821    139397          12               Raleigh         South Atlantic
16  TN   Tennessee         42146    109158          16               Nashville       East South Central
17  NE   Nebraska          77358    200358          37               Lincoln         West North Central
18  IL   Illinois          57918    150007          21               Springfield     East North Central
19  KS   Kansas            82282    213110          34               Topeka          West North Central
20  NH   New Hampshire      9351     24219           9               Concord         New England
21  DE   Delaware           2489      6447           1               Dover           South Atlantic
22  NJ   New Jersey         8722     22590           3               Trenton         Mid-Atlantic
23  AK   Alaska           656424   1700139          49               Juneau          Pacific
24  NM   New Mexico       121598    314939          47               Santa Fe        Mountain
25  NY   New York          54475    141089          11               Albany          Mid-Atlantic
26  CA   California       163707    424002          31               Sacramento      Pacific
27  MO   Missouri          69709    180546          24               Jefferson City  West North Central
28  OK   Oklahoma          69903    181049          46               Oklahoma City   West South Central
29  PA   Pennsylvania      46058    119291           2               Harrisburg      Mid-Atlantic
30  SC   South Carolina    32007     82898           8               Columbia        South Atlantic
31  WY   Wyoming           97818    253349          44               Cheyenne        Mountain
32  SD   South Dakota      77122    199745          40               Pierre          West North Central
33  UT   Utah              84904    219902          45               Salt Lake City  Mountain
34  AL   Alabama           52423    135775          22               Montgomery      East South Central
35  VT   Vermont            9615     24903          14               Montpelier      New England
36  AR   Arkansas          53182    137742          25               Little Rock     West South Central
37  WA   Washington        71303    184674          42               Olympia         Pacific
38  AZ   Arizona          114006    295276          48               Phoenix         Mountain
39  WV   West Virginia     24231     62759          35               Charleston      South Atlantic
40  LA   Louisiana         51844    134275          18               Baton Rouge     West South Central
41  MA   Massachusetts     10555     27337           6               Boston          New England
42  FL   Florida           65758    170313          27               Tallahassee     South Atlantic
43  GA   Georgia           59441    153953           4               Atlanta         South Atlantic
44  HI   Hawaii            10932     28313          50               Honolulu        Pacific
45  MD   Maryland          12407     32135           7               Annapolis       South Atlantic
46  CO   Colorado         104100    269620          38               Denver          Mountain
47  MI   Michigan          98810    250738          26               Lansing         East North Central
48  MN   Minnesota         86943    225182          32               Saint Paul      West North Central
49  CT   Connecticut        5544     14358           5               Hartford        Mid-Atlantic
50  NV   Nevada           110567    286368          36               Frankfort       Mountain
=========================================================================================================
Do you want to sort the list in alphabetical order (y/n)?```
19. When prompted, type y and press Enter:
```                                 United States of America
=========================================================================================================
# Abbrv State Name        SqrMls     Km2        to Union            Capital         Region
---------------------------------------------------------------------------------------------------------
1  AL   Alabama           52423    135775          22               Montgomery      East South Central
2  AK   Alaska           656424   1700139          49               Juneau          Pacific
3  AZ   Arizona          114006    295276          48               Phoenix         Mountain
4  AR   Arkansas          53182    137742          25               Little Rock     West South Central
5  CA   California       163707    424002          31               Sacramento      Pacific
6  CO   Colorado         104100    269620          38               Denver          Mountain
7  CT   Connecticut        5544     14358           5               Hartford        Mid-Atlantic
8  DE   Delaware           2489      6447           1               Dover           South Atlantic
9  FL   Florida           65758    170313          27               Tallahassee     South Atlantic
10  GA   Georgia           59441    153953           4               Atlanta         South Atlantic
11  HI   Hawaii            10932     28313          50               Honolulu        Pacific
12  ID   Idaho             83574    216456          43               Boise           Mountain
13  IL   Illinois          57918    150007          21               Springfield     East North Central
14  IN   Indiana           36420     94328          19               Indianapolis    East North Central
15  IA   Iowa              56276    145754          29               Des Moines      West North Central
16  KS   Kansas            82282    213110          34               Topeka          West North Central
17  KY   Kentucky          40411    104665          15               Frankfort       New England
18  LA   Louisiana         51844    134275          18               Baton Rouge     West South Central
19  ME   Maine             35387     91653          23               Augusta         New England
20  MD   Maryland          12407     32135           7               Annapolis       South Atlantic
21  MA   Massachusetts     10555     27337           6               Boston          New England
22  MI   Michigan          98810    250738          26               Lansing         East North Central
23  MN   Minnesota         86943    225182          32               Saint Paul      West North Central
24  MS   Mississippi       48434    125443          20               Jackson         East South Central
25  MO   Missouri          69709    180546          24               Jefferson City  West North Central
26  MT   Montana          147046    380850          41               Helena          Mountain
27  NE   Nebraska          77358    200358          37               Lincoln         West North Central
28  NV   Nevada           110567    286368          36               Frankfort       Mountain
29  NH   New Hampshire      9351     24219           9               Concord         New England
30  NJ   New Jersey         8722     22590           3               Trenton         Mid-Atlantic
31  NM   New Mexico       121598    314939          47               Santa Fe        Mountain
32  NY   New York          54475    141089          11               Albany          Mid-Atlantic
33  NC   North Carolina    53821    139397          12               Raleigh         South Atlantic
34  ND   North Dakota      70704    183123          39               Bismarck        West North Central
35  OH   Ohio              44828    116103          17               Columbus        East North Central
36  OK   Oklahoma          69903    181049          46               Oklahoma City   West South Central
37  OR   Oregon            98386    254819          33               Salem           Pacific
38  PA   Pennsylvania      46058    119291           2               Harrisburg      Mid-Atlantic
39  RI   Rhode Island       1545      4002          13               Providence      New England
40  SC   South Carolina    32007     82898           8               Columbia        South Atlantic
41  SD   South Dakota      77122    199745          40               Pierre          West North Central
42  TN   Tennessee         42146    109158          16               Nashville       East South Central
43  TX   Texas            268601    695676          28               Austin          West South Central
44  UT   Utah              84904    219902          45               Salt Lake City  Mountain
45  VT   Vermont            9615     24903          14               Montpelier      New England
46  VT   Vermont            9615     24903          14               Montpelier      New England
47  WA   Washington        71303    184674          42               Olympia         Pacific
48  WV   West Virginia     24231     62759          35               Charleston      South Atlantic
49  WI   Wisconsin         65503    169653          30               Madison         East North Central
50  WY   Wyoming           97818    253349          44               Cheyenne        Mountain
=========================================================================================================
Press any key to continue . . .```

Introduction

To store a very large number that cannot fit in a double-word, you can consider a combination of 64 bits. The group can also be referred to as a quad-word. A quad-word is very large. It can store numbers in the range of -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.

If you declare an integer variable using the var keyword and initialize it with a value between 2,147,484,647 and 9,223,372,036,854,775,807, the compiler concludes that the memory needed to store that variable is 64 bits:

Long Integers

To let you use a variable that can hold very large numbers that may require up to 64 bits, the C# language provides a data type named long. You can use it to declare a variable.

To let you display an unsigned integer to the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a long argument. Their syntaxes are:

```public static void Write(long value);
public static void WriteLine(long value);```

Here is an example:

```using static System.Console;

public class Exercise
{
public static int Main()
{
long areaSqrMiles = 3705407;

WriteLine("Country Statistics");
WriteLine("Area: " + areaSqrMiles + " Sqr Miles)");

return 0;
}
}```

As always, you can also use the var keyword to declare the variable. When initializing the variable, don't use the official thousands separator. Instead, you can either type the number as it is or you can use the underscore(s) to separate the thousands. Here are examples:

```using static System.Console;

public class Exercise
{
static int Main()
{
long areaSqrMiles = 3705407;
long areaSqrKms   = 9_596_961;
long population = 1_403_500_365;

WriteLine("Country Statistics");
Write("Area: ");
Write(areaSqrKms);
Write(" Sqr Kms (");
Write(areaSqrMiles);
WriteLine(" Sqr Miles)");
Write("Population: ");
WriteLine(population);

return 0;
}
}```

As stated previously, if you initialize the variable with a value lower than 2,147,484,647, the compiler would allocate 32 bits of memory for it. If you initialize the variable with a value between 2,147,484,647 and 9,223,372,036,854,775,807, the compiler would allocate 64 bits of memory for it. If the value is higher than 9,223,372,036,854,775,807, which is too large, the compiler would present an error:

This means that you should limit the values assigned to integral variables to 64 bits, which is very significant. Here is an example:

```using static System.Console;

public class Exercise
{
static void Main()
{
var countryArea = 5638648;

Write("Country Area: ");
Write(countryArea);
Write("km2\n");
}
}```

This would produce:

```Country Area: 5638648km2
Press any key to continue . . .```

As mentioned for other integral types, you can initialize a long variable with a hexadecimal value.

Although the long data type is used for large numbers, 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 a long variable to store a number that would fit in 32 bits:

```using static System.Console;

public class Exercise
{
static void Main()
{
long countryArea;

countryArea = 5638648L;

Write("Country Area: ");
Write(countryArea);
Write("km2\n");
}
}```

Therefore, keep in mind that an int, a uint, ashort, or a ushort can fit in a long variable.

Unsigned Long Integers

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.

To let you display an unsigned long integer to the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a long argument. Their syntaxes are:

```public static void Write(ulong value);
public static void WriteLine(ulong value);```

Real Numbers

Introduction

A real number is a number that displays a decimal part. This means that the number can be made of two sections separated by a symbol that is referred to as the Decimal Separator or Decimal Symbol. This symbol is different by language, country, group of languages, or group of countries. In US English, this symbol is the period as can be verified from the Regional (and Language) Settings of the Control Panel:

On both sides of the decimal symbol, digits are used to specify the value of the number. The number of digits on the right side of the symbol determines how much precision the number offers.

Floating-Point Numbers

The integers we have used so far have the main limitation of not allowing decimal values. C# provides floating values that would solve this problem. The most fundamental floating variable is declared with the float keyword. A variable declared as float can store real numbers that range from Â±1.5 xÂ 10−45 to Â±3.4 xÂ 1038 with a precision of 7 digits in 32 bits. Here is an example:

```class Exercise
{
static void Main()
{
float distance;
}
}```

To let you display a floating-point number with single-precision to the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a float argument. Their syntaxes are:

```public static void Write(object value);
public static void WriteLine(object value);```

Double-Precision Numbers

When a variable is larger than the float can handle and requires more precision, you should declare it using either the var or the the double keyword.

To let you display a floating-point number with double-precision to the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a double argument. Their syntaxes are:

```public static void Write(double value);
public static void WriteLine(double value);```

Here is an example:

```using static System.Console;

public class Exercise
{
static void Main()
{
var number = 62834.9023;

WriteLine("Number: " + number);
}
}```

This would produce:

```Number: 62834.9023
Press any key to continue . . .```

A variable declared as double uses 64 bits to store very large numbers ranging from Â±5.0 x 10−324 to Â±1.7 x Â10308 with a precision of 15 or 16 digits. Because the double data type provides a better result with better precision than the float, whenever you declare a variable using either the var or the float keyword and assign it a value, the compiler allocates 64 bits to store the values of the variable. If you insist on the variable being treated as float, when assigning it a value, add an f or an F suffix to the value. Here is an example:

```using static System.Console;

public class Exercise
{
static void Main()
{
float distance;

distance = 248.38F;

Write("Distance = ");
Write(distance);
WriteLine("km\n");
}
}```

This would produce:

`Distance = 248.38km`

Remember that if you declare the variable as var and want to treat it as a value with single precision, add an f or an F suffix to the value assigned to it. Here is an example:

```using static System.Console;

public class Exercise
{
static void Main()
{
var  number = 62834.9023F;

Write("Number: ");
WriteLine(number);
}
}```

On the other hand, if you want a value to be treated with double-precision, add a d or a D suffix to it. Here is an example:

```class Exercise
{
static void Main()
{
var  number = 62834.9023D;

Write("Number: ");
WriteLine(number);
}
}```

Practical Learning: Using a Single-Precision Variable

1. To start a new application, on the main menu of Microsoft Visual Studio, click File -> New -> Project...
2. In the middle list, click Console App (.NET Framework)
3. Change the Name to Chemistry6 and press Enter
4. To create a class, on the main menu, click Project -> Add Class...
5. In the middle list, mahe sure Class is selected.
Change the Name of the file to Element
7. To use a double-precision value, change the class as follows:
```namespace Chemistry6
{
public enum Phase
{
Gas,
Liquid,
Solid,
Unknown
}

public class Element
{
public string Symbol       { get; set; } = "H";
public string ElementName  { get; set; } = "Hydrogen";
public int    AtomicNumber { get; set; } = 1;
public float  AtomicWeight { get; set; } = 1.008F;
public Phase  Phase        { get; set; } = Phase.Gas;

public Element()
{
}

public Element(int number)
{
AtomicNumber = number;
}

public Element(string symbol)
{
Symbol = symbol;
}

public Element(int number, string symbol, string name, float mass)
{
ElementName  = name;
AtomicWeight = mass;
AtomicNumber = number;
Symbol       = symbol;
Phase        = Phase.Unknown;
}

public Element(int number, string symbol, string name, float mass, Phase phase)
{
ElementName  = name;
AtomicWeight = mass;
Phase        = phase;
AtomicNumber = number;
Symbol       = symbol;
}
}
}```
8. In the Solution Explorer, right-click Program and click Rename
9. Type Chemistry to get Chemistry.cs and press Enter
10. Read the text on the message box and click Yes
11. In the Solution Explorer, double-click Chemistry.cs to access it
12. Change the document as follows:
```using static System.Console;

namespace Chemistry6
{
class Chemistry
{
private static void Describe(Element e)
{
WriteLine("Chemistry - " + e.ElementName);
WriteLine("------------------------");
WriteLine("Symbol:        " + e.Symbol);
WriteLine("Element Name:  " + e.ElementName);
WriteLine("Atomic Number: " + e.AtomicNumber);
WriteLine("Atomic Weight: " + e.AtomicWeight);
WriteLine("Phase:         " + e.Phase);
}

public static int Main(string[] args)
{
Element elm = null;

Element  H = new Element(1, "H", "Hydrogen", 1.008f, Phase.Gas);
Element He = new Element(2, "He", "Helium", 4.002602f, Phase.Gas);
Element Li = new Element(3, "Li", "Lithium", 6.94f, Phase.Solid);
Element Be = new Element(4, "Be", "Beryllium", 9.0121831f, Phase.Solid);
Element  B = new Element(5, "B", "Boron", 10.81f, Phase.Solid);
Element  C = new Element(number: 6, symbol: "C", name: "Carbon", mass: 12.011f, phase: Phase.Solid);
Element  N = new Element(7, "N", "Nitrogen", 14.007f, Phase.Gas);
Element  O = new Element(8, "O", "Oxygen", 15.999f, Phase.Gas);
Element  F = new Element(9, "F", "Fluorine", 15.999f, Phase.Gas);
Element Ne = new Element("Ne") { AtomicNumber = 10, ElementName = "Neon", AtomicWeight = 20.1797f, Phase = Phase.Gas };
Element Na = new Element(11, "Na", "Sodium", 22.98976928f, Phase.Solid);
Element Mg = new Element(12, "Mg", "Magnesium", 24.305f, Phase.Solid);
Element Al = new Element(13, "Al", "Aluminium", 26.9815385f, Phase.Solid);
Element Si = new Element() { ElementName = "Silicon", AtomicWeight = 28.085f, Symbol = "Si", AtomicNumber = 14, Phase = Phase.Solid };
Element  P = new Element() { ElementName = "Phosphorus", AtomicWeight = 30.973761998f, Symbol = "P", AtomicNumber = 15, Phase = Phase.Solid };
Element  S = new Element(16, "S", "Sulfur", 32.06f, Phase.Solid);
Element Cl = new Element(17, "Cl", "Chlorine", 35.45f, Phase.Gas);
Element Ar = new Element(18, "Ar", "Argon", 39.792f, Phase.Gas);
Element  K = new Element(19, "K", "Potassium", 39.0983f, Phase.Solid);
Element Ca = new Element(20, "Ca", "Calcium", 40.078f, Phase.Solid);
Element Sc = new Element(21, "Sc", "Scandium", 44.955908f, Phase.Solid);

WriteLine("Chemistry - Periodic Table");
WriteLine("------------------------------------------------");

try
{
Write("To get more information about an element, type its atomic number, its chemical symbol, or its name: ");

Clear();

{
case "ar":
case "18":
case "Argon":
elm = Ar;
break;
case "al":
case "aluminium":
case "13":
elm = Al;
break;
case "5":
case "b":
case "boron":
elm = B;
break;
case "4":
case "be":
case "beryllium":
elm = Be;
break;
case "6":
case "c":
case "carbon":
elm = C;
break;
case "calcium":
case "20":
case "ca":
elm = Ca;
break;
case "chlorine":
case "cl":
case "17":
elm = Cl;
break;
default:
WriteLine("You must type a valid element name, atomic number, or chemical symbol.");
break;
case "9":
case "fluorine":
case "f":
elm = F;
break;
case "1":
case "h":
case "hydrogen":
elm = H;
break;
case "2":
case "he":
case "helium":
elm = He;
break;
case "potassium":
case "19":
case "k":
elm = K;
break;
case "3":
case "li":
case "lithium":
elm = Li;
break;
case "magnesium":
case "mg":
case "12":
elm = Mg;
break;
case "7":
case "n":
case "nitrogen":
elm = N;
break;
case "na":
case "11":
case "sodium":
elm = Na;
break;
case "ne":
case "10":
case "neon":
elm = Ne;
break;
case "8":
case "o":
case "oxygen":
elm = O;
break;
case "p":
case "15":
case "phosphorus":
elm = P;
break;
case "Sulfur":
case "16":
case "s":
elm = S;
break;
case "sc":
case "21":
case "scandium":
elm = Sc;
break;
case "si":
case "silicon":
case "14":
elm = Si;
break;
}

Describe(elm);
}
catch (System.NullReferenceException nre)
{
WriteLine(nre.Message);
}

WriteLine("======================================");

return 0;
}
}
}```
```Chemistry - Periodic Table
------------------------------------------------
ymbol, or its name:```
14. When prompted, type SCANDIUM and press Enter
```Chemistry - Scandium
------------------------
Symbol:        Sc
Element Name:  Scandium
Atomic Number: 21
Atomic Weight: 44.95591
Phase:         Solid
======================================
Press any key to continue . . .```

Decimal

The decimal data type can be used to declare a variable that would hold significantly large values that can be stored in a combination of 128 bits. You declare such a variable using the decimal keyword. The values stored in a decimal variable can range from Â±1.0 xÂ 10−28 to Â±7.9 xÂ 1028 with a precision of 28 to 29 digits. Because of this high level of precision, the decimal data type is suitable for currency values.

After declaring a decimal variable, you can initialize it with a natural number. To indicate that the variable holds a decimal value, when initializing it, add an m or an M suffix to its value.

To let you display a decimal number to the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a decimal argument. Their syntaxes are:

```public static void Write(decimal value);
public static void WriteLine(decimal value);```

Here is an example:

```class Exercise
{
static void Main()
{
decimal hourlySalary;

hourlySalary = 24.25M;

Write("Hourly Salary = ");
WriteLine(hourlySalary);
WriteLine();
}
}```

This would produce:

`Hourly Salary = 24`

As seen in previous sections and this one, when declaring and initializing a real variable, the suffix you give to its assigned value indicates to the compiler the actual type of value and the type of memory that would be allocated for the variable:

• If the value receives an f or an F suffix, it is considered a floating point number with single precision

• If the value receives a d or a D suffix, it is considered a floating point number with double precision

• If the value receives an m or an M suffix, it is considered a large decimal number

Consider the following program:

```using static System.Console;

public class Program
{
static void Main()
{
Write("560 / 672 = ");
WriteLine(560 / 672);
}
}```

The purpose of this program is to get the division of 560 by 672. This would produce:

```560 / 672 = 0
Press any key to continue . . .```

Notice that, when such numbers are submitted to the program, the compiler decides that these are integers and the result produces 0. If you write such an equation and want the result to appear as a real number, you must explicitly indicate it to the compiler. One way you can do this consists of adding decimal places to at least one of the numbers. Here is an example:

```using static System.Console;

public class Program
{
static void Main()
{
Write("560 / 672 = ");
WriteLine(560.00 / 672.00);
}
}```

This time, the compiler will conclude that the value is a floating-point number; but which one? By default, the compiler would apply the double data type. This version of the program would produce:

```560 / 672 = 0.833333333333333
Press any key to continue . . .```

If you want to indicate that the value is a float, a double, or a decimal, add the appropriate prefix to it: f, F, d, D, m, or M. Here are examples:

```using static System.Console;

public class Program
{
static void Main()
{
Write("560 / 672 = ");
WriteLine(560F / 672f);
}
}```

This version of the program would produce:

```560 / 672 = 0.8333333
Press any key to continue . . .```

Practical Learning: Ending the Lesson