Floor average and ceil average

function floor_average(x, y) {return (x & y) + ((x ^ y) >> 1);} function ceil_average(x, y) {return (x | y) - ((x ^ y) >> 1);} console.log(floor_average(15,6)); // 10 console.log(ceil_average(15,6)); // 11 console.log(floor_average(12,28)); // 20 console.log(ceil_average(12,28)); // 20