How can a computer check whether a positive whole number is a power of two in a single step, without a loop?
Hint 1Write 8, 16 and 20 in binary.
Hint 2What happens to the binary digits when you subtract 1 from a power of two?
A power of two in binary is a single 1 followed by zeros, such as 1000.
Subtracting 1 turns it into all ones below that place: 1000 − 1 = 0111.
So n AND (n − 1) is 0 exactly when n has a single 1 bit.
Any other positive number keeps its highest 1 bit after the AND, so the result is not 0.
Test: n > 0 and (n AND (n − 1)) = 0.
Where it lands: n > 0 and n AND (n − 1) equals 0.
The trap: Forgetting n = 0, which passes the AND test but is not a power of two.
What a tutor might ask next: How would you count the 1 bits in a number using the same trick?
Now do one out loud. In the interview you think aloud with a tutor. Try a Computer Science problem with hints, follow-ups and Mia's feedback on how you think.
Problems in your subject, answered out loud on the page. Take hints when stuck, answer the follow-ups, and see how your thinking comes across.
Oxbridge Interview Rehearsal: two subjects
£249 once. No VAT is charged.
Introductory price £249 until 31 December, then £399.
Rehearse every problem in two subjects you choose, with hints, follow-ups and Mia's marks, for 12 months.
All 8 problems in each of your two subjects, chosen after you pay
Hints when you are stuck, then the tutor's follow-up questions
Mia's marks on up to 60 attempts a day, within a fair-use allowance for each interview season: thinking aloud, using hints, checking, reasoning
Your next problem picked from your weakest skill
Your latest 300 attempts saved, with re-attempts side by side
Access for 12 months, until 18 November 2027. Choose your subjects after paying, on a free account. Full refund within 14 days, for any reason.
By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right. Your full refund within 14 days, for any reason, still applies.
Oxbridge Interview Rehearsal: all subjects
£349 once. No VAT is charged.
Introductory price £349 until 31 December, then £499.
Every problem in all seven subjects, for joint courses and for practising beyond your own subject.
All 56 problems: Maths, Computer Science, Engineering, Physics, Economics, Law and PPE
Hints when you are stuck, then the tutor's follow-up questions
Mia's marks on up to 60 attempts a day, within a fair-use allowance for each interview season: thinking aloud, using hints, checking, reasoning
Your next problem picked from your weakest skill
Your latest 300 attempts saved, with re-attempts side by side
Access for 12 months, until 18 November 2027. Use it on a free account. Full refund within 14 days, for any reason.
By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right. Your full refund within 14 days, for any reason, still applies.