How to judge the existence of a value and a Range

Source: Internet
Author: User

Wchar wcvalue;

How can we determine that wcvalue is one of the ten numbers 0-9?

Many people will write: If (wcvalue> = 0x30 & wcvalue <= 0x39)

Very intuitive, but a little ugly.

In fact, you can change it:

If (wcValue-0x30 <0x10)

However, a problem occurs. Wcvalue is treated as a number as a signed number. If wcvalue is smaller than 0x30, the calculation result is considered as a negative number. To solve this problem, you only need to forcibly convert it to the DWORD type. In this way, negative numbers are considered as a very huge positive integer. (Here, we should look at the complement knowledge)

Therefore, it is written as follows:

If (DWORD) wcValue-0x30 <0x10)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.