If I have a range of say 000080-0007FF
and I want to see if a char containing hex is within that range, how can I do it?
Example
char t = 0xd790;
if (t is within range of 000080-0007FF) // true
wchar_t t = 0xd790;
if (t >= 0x80 && t <= 0x7ff) ...
In C++, characters are interchangeable with integers and you can compare their values directly.
Note that I used wchar_t
, because the char
data type can only hold values up to 0xFF.
unsigned short t = 0xd790;
if (t >= 0x80 && t <= 0x7ff) ...
由于 char 的最大值为 0xFF,因此您不能使用它来比较十六进制数字多于 2 的任何内容。
由于计算机上的十六进制只不过是一种打印数字(如十进制)的方式,因此您也可以与普通的旧基 10 整数进行比较。
if( (t >= 128) && (t <= 2047) )
{
}
更具可读性。