I. Definition
In Microsoft Visual Studio/vc98/include/windef. h of vc6.0, byte, word, DWORD are defined.
Typedef unsigned long DWORD;
Typedef unsigned char byte;
Typedef unsigned short word;
In Visual C ++ 6.0, the char type is 1 byte, the short type is 2 bytes, And the int and long types are both 4 bytes. Therefore, we can consider that byte and word, the variables defined by DWORD obtain 1-byte, 2-byte, and 4-byte memory respectively, which are consistent with the literal meanings of byte and word and DWORD.
That is:
Byte = unsigned char (exactly the same): 8 digits
WORD = unsigned short (completely equivalent): 16 bits
DWORD = unsigned long (completely equivalent): 32-bit
The following are some macros that are usually used less frequently:
Ii. Window macros
1.Lobyte (From the given 16Bit value to extract low byte)
Byte lobyte (
Word wvalue // value from which low-order byte is retrieved
);
# Define lobyte (w) (byte) (w ))
For example, word w =-0x1234; // W is stored in the memory as a complement: 0 xedcc, that is, 0xcc (low address) 0xed (high address)
Printf ("W low byte: % x/N", lobyte (w); // input: W low byte: CC
2.Hibyte (From the given 16Bit value to extract high byte)
Byte hibyte (
Word wvalue // value from which high-order byte is retrieved
);
# Define hibyte (w) (byte) (Word) (W)> 8) & 0xff ))
For example: printf ("W high byte: % x/N", hibyte (w); // output: W high byte: Ed
3.Loword (From the given 32Extract low-level word from bits)
Word loword (
DWORD dwvalue // value from which low-order word is retrieved
);
# Define loword (L) (Word) (l ))
For example, dword l = 0x12345678; // L is stored in the memory as follows: 0 x, 0x56, 0x34,0x12
Printf ("l low-level characters: % x/N", loword (l); // output: l low-level words: 5678
4.Hiword (From the given 32Extracts high-level word from bits)
Word hiword (
DWORD dwvalue // value from which high-order word is retrieved
);
# Define hiword (L) (Word) (DWORD) (l)> 16) & 0 xFFFF ))
For example: printf ("L high character: % x/N", hiword (l); // output: l high character: 1234
5.Makeword (Concatenates two unsigned character values into a 16Bitwise integer)
Word makeword (
Byte blow, // low-order byte of short Value
Byte bhigh // High-Order byte of short Value
);
# Define makeword (A, B )/
(Word) (byte) (a) | (Word) (byte) (B) <8 ))
For example, byte blow = 0x34, bhigh = 0x12;
Printf ("makeword (% x, % x) = % x/N", blow, bhigh, makeword (blow, bhigh ));
Output result: makeword (1234) =
6.Makelong(Returns twoBit value is connected to a 32Bitwise integer)
DWORD makelong (
Word wlow, // low-order word of long value
Word whigh // high-order word of long value
);
# Define makelong (A, B )/
(Long) (Word) (a) | (DWORD) (Word) (B) <16 ))
For example, word vlow = 0x5678, vhigh = 0x1234;
Printf ("makelong (% x, % x) = % x/N", vlow, vhigh, makelong (vlow, vhigh ));
Output: makelong (5678,1234) = 12345678
From: http://blog.csdn.net/zhangyang0402/archive/2008/12/13/3509850.aspx