Previous power of 2

后端 未结 11 1446
一整个雨季
一整个雨季 2020-11-30 05:42

There is a lot of information on how to find the next power of 2 of a given value (see refs) but I cannot find any to get the previous power of two.

The only way I f

11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 06:33

    Here is a one liner for posterity (ruby):

    2**Math.log(input, 2).floor(0)
    

提交回复
热议问题