Domanda di colloquio di King

Half an integer without using * or / in your preferred language.

Risposte di colloquio

Anonimo

3 ott 2017

So I guess you could bit shift it by 1 to get half the result n >> 1

1

Anonimo

8 gen 2018

float half = number & 0x1? number>>1+.5f : number>>1

Anonimo

7 lug 2018

Well this was a long time ago, but for those who still interested : Just a one bit right shifting the integer would give you the half of it Assuming we have a number : int n = 150; Half will be equal to : float half = (n >> 1) + 0.5f; Happy coding!