Home

Using Variables: 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 LO Byte. It is sometimes referred to as 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 HI 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 LO Word, or LOWORD. The group of the left 16 bits, or the left Word, is called the High Order Word, or HI 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 = 0XFFFFFFFF = 0xFFFFFFFF
 

Practical LearningPractical Learning: Using Unsigned Integers

  1. Change the file as follows:
     
    using System;
    
    class Program
    {
        static void Main()
        {
            byte shirts;
            byte pants;
            ushort otherItems;
    
            shirts     = 4;
            pants      = 0;
            otherItems = 3;
    
            Console.WriteLine("-/- Georgetown Cleaning Services -/-");
            Console.WriteLine("========================");
            Console.WriteLine("------------------------");
            Console.WriteLine("Item Type  Qty");
            Console.WriteLine("------------------------");
            Console.Write("Shirts      ");
            Console.WriteLine(shirts);
            Console.Write("Pants       ");
            Console.WriteLine(pants);
            Console.Write("Other Items ");
            Console.WriteLine(otherItems);
            Console.WriteLine("========================");
            Console.WriteLine();
        }
    }
  2. Execute the program to see the result 
  3. Close the DOS window

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 large numbers that would not fit in a word.

To use a variable that would hold quite large numbers, 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.

Here is an example:

using System;

class NumericRepresentation
{
	static void Main()
	{
		int CoordX;
		int CoordY;
	
		CoordX = 12;
		CoordY = -8;

		Console.Write("Cartesian Coordinate System: ");
		Console.Write("P(");
		Console.Write(CoordX);
		Console.Write(", ");
		Console.Write(CoordY);
		Console.WriteLine(")\n");
	}
}

When executed, the program would produce:

Cartesian Coordinate System: P(12, -8)

Unsigned Integers

If the variable must hold only positive natural numbers, you can declared it using the uint keyword. The uint keyword is used to identify a 32-bit positive integer whose value would range from 0 to 2,147,484,647. Here is an example:

using System;

class NumericRepresentation
{
	static void Main()
	{
		uint DayOfBirth;
		uint MonthOfBirth;
		uint YearOfBirth;
	
		DayOfBirth   = 8;
		MonthOfBirth = 11;
		YearOfBirth  = 1996;

		Console.WriteLine("Red Oak High School");
		Console.Write("Student Date of Birth: ");
		Console.Write(MonthOfBirth);
		Console.Write("/");
		Console.Write(DayOfBirth);
		Console.Write("/");
		Console.Write(YearOfBirth);
		Console.WriteLine();
	}
}

This would produce:

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

Practical LearningPractical Learning: Using Unsigned Integers

  1. To use unsigned variables, change the file as follows:
     
    using System;
    
    class Program
    {
        static void Main()
        {
            byte shirts;
            byte pants;
            ushort otherItems;
    
            uint orderDay;
            uint orderMonth;
            uint orderYear;
    
            shirts     = 4;
            pants      = 0;
            otherItems = 3;
            orderDay = 15;
            orderMonth = 7;
            orderYear = 2002;
    
            Console.WriteLine("-/- Georgetown Cleaning Services -/-");
            Console.WriteLine("========================");
            Console.Write("Order Date: ");
            Console.Write(orderMonth);
            Console.Write('/');
            Console.Write(orderDay);
            Console.Write('/');
            Console.WriteLine(orderYear);
            Console.WriteLine("------------------------");
            Console.WriteLine("Item Type  Qty");
            Console.WriteLine("------------------------");
            Console.Write("Shirts      ");
            Console.WriteLine(shirts);
            Console.Write("Pants       ");
            Console.WriteLine(pants);
            Console.Write("Other Items ");
            Console.WriteLine(otherItems);
            Console.WriteLine("========================");
            Console.WriteLine();
        }
    }
  2. Execute the program. This would produce:
     
    -/- Georgetown Cleaning Services -/-
    ========================
    Order Date: 7/15/2002
    ------------------------
    Item Type  Qty
    ------------------------
    Shirts      4
    Pants       0
    Other Items 3
    ========================
    
    Press any key to continue . . .
  3. Close the DOS window
 

Previous Copyright © 2006-2007 FunctionX, Inc. Next