Interview Questions: determine whether an integer is an even number. At least three methods are required.

Source: Internet
Author: User

Just a few days after I came to Shanghai, I was looking for a job. When I was looking for a job, I met a company's interview question:

You must use at least three methods to determine whether an integer is an even number.

The time was too short. At that time, I only thought of two methods:

1. If the remainder n % 2 = 0 for 2 is an even number

2. the bitwise operation N & 1 = 0 is an even number (I wrote N & 0xfe at the time, a little nervous)

 

I'm not sure about the third method at the moment, but I think of it as follows:

If we get the last bit of N, we can see whether it can be divisible by 2, but the operation of getting the last bit is much more complicated than getting the remainder directly. Do you know if this can be calculated?

 

If you know something, please tell me. Thank you.

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.