Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.

def max_gap(N):
    xs = bin(N)[2:].strip('0').split('1')
    return max([len(x) for x in xs])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #A #binary #gap #positive #integer #N #maximal #sequence #consecutive #zeros #surrounded #ends #binary #representation
ADD COMMENT
Topic
Name
9+6 =