Frage im Vorstellungsgespräch bei Ubisoft

How to check if a number is divisible by 16 without using operator / or % ?

Antworten zu Vorstellungsgespräch

Anonym

5. Aug. 2018

Bit wise right shift four times, if integer then divisible.

1

Anonym

23. März 2019

If a number is divisible by 2^n, do bitwise right shift n times and then bitwise left shift n times to get back the same number.

1

Anonym

2. Okt. 2017

should do using bit-wise operators

1

Anonym

22. Juli 2018

I will run a loop that'll subtract 16 from the number. If result is zero than it is divisible else if it goes less than zero than its is not.

Anonym

9. Jän. 2020

if(16>>4 == 0 ) True; else False

1

Anonym

9. Jän. 2020

The above condition should be 1 instead of 0. if(16>>4 == 1 ) True; else False

Anonym

19. Feb. 2019

for(int i=0;in) { break; } //number is not divisible by 16 //which will be decided by the flag } }

Anonym

19. Feb. 2019

Sorry for that incompleted answer ! I want to say that simply use a loop upto n and multiply each number with 16 and store in a variable and then go for a check if it is matched by n or not. If matched then flag==true else break;