Pregunta de entrevista de King

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

Respuestas de entrevistas

Anónimo

3 oct 2017

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

1

Anónimo

8 ene 2018

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

Anónimo

7 jul 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!