Hi, 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 this? Thanks a lot.
Example
char t = 0xd790;
if (t is within range of 000080-0007FF) // true
Thanks
Hi, 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 this? Thanks a lot.
Example
char t = 0xd790;
if (t is within range of 000080-0007FF) // true
Thanks
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.
@Greg, I tried it and I get warning: comparison is always false due to limited range of data type
Ok just read your fix
unsigned short t = 0xd790;
if (t >= 0x80 && t <= 0x7ff) ...
Since a char has a max value of 0xFF you cannot use it to compare anything with more hex digits than 2.
Since hex on a computer is nothing more than a way to print a number (like decimal), you can also do your comparison with plain old base 10 integers.
if( (t >= 128) && (t <= 2047) ) { }
More readable.