WORD (Type)
A 16-bit unsigned integer. This type is defined as follows:
typedef unsigned short WORD;
Description
The WORD type represents an unsigned integer that can store values from 0 to 65535. It is commonly used in Windows programming for various purposes, including:
- Representing bit flags or options.
- Storing small numerical values.
- Interacting with hardware or low-level system components.
- Data structures where a 16-bit size is optimal.
This type is equivalent to the standard C++ `unsigned short` type. On most Windows systems, it occupies 2 bytes of memory.
Usage Example
Here's a simple example demonstrating the use of the WORD type:
#include <windows.h>
#include <iostream>
int main() {
// Declare a WORD variable
WORD statusFlags = 0x0001; // Represents a status bit
std::cout << "Initial status flags: " << statusFlags << std::endl;
// Set another flag
statusFlags |= 0x0002; // Set the second bit
std::cout << "Updated status flags: " << statusFlags << std::endl;
// Check a specific flag
if (statusFlags & 0x0001) {
std::cout << "Status flag 1 is set." << std::endl;
}
// Example of assigning a value
WORD segmentNumber = 12345;
std::cout << "Segment number: " << segmentNumber << std::endl;
return 0;
}
Related Types
| Type | Description |
|---|---|
| DWORD | A 32-bit unsigned integer. |
| SHORT | A 16-bit signed integer. |
| USHORT | An alias for WORD, also a 16-bit unsigned integer. |