1

My goal is to get nearest bigger number than an input integer that is two to the n.

For example, what should nearestbigger be?

integerinput = [2016, 300, 9001]
for x in integerinput:
    print(nearestbigger(x))

Expected Output

2048
512
16384
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Marek Tran
  • 23
  • 5
  • I've reopened this question because OP is seeking a python soluiton, whereas the so-called duplicate is cross-language, and in fact there is now python solution there. – shx2 Jul 17 '16 at 18:13

1 Answers1

1
def nearesbigger(n):
    if n <= 0:
        return 1
    return 2 ** (n-1).bit_length()
shx2
  • 61,779
  • 13
  • 130
  • 153