Tags » Bit

Reverse bits in an integer

Say this integer has M bits

def reverse_bits(n, M):
    N = 1 << M
    r = n # will store the bit-revevrsed pattern
    for i in xrange(M):
        n >> 1
        r << 1
        r |= n&1 # Give LSB of n to r
    r &= N-1 # N-1 is a mask, will clear all bits more significant than N-1
    return r

# A improved version
def reverse(n, M):
    N = 1 << M
    count = M -1
    r = n

    while n != 0:
        n >> 1
        r << 1
        r |= n&1
        count -= 1
    r << count
    r &= N-1
    return r

Ptsd And Training

I ve done a bit of looking but when I look for information on coping skills for those who consider themselves “athletes” and dealing with PTSD or just mental illness in general I haven t found a lot of information. 64 more words

Jenna Marbles would be great on a blind date

I’m still a little confused about the genders of both parties involved, but it seemed like a successful time.


If I Were Just A Little Bit Butch — Medium

In the early days of online job searches, I signed up with this online employment company. I detailed my major in Spanis…

[HR] Sansa and XOR

Problem Statement

Sansa has an array. She wants to find the value obtained by XOR-ing the contiguous subarrays, followed by XOR-ing the values thus obtained. 159 more words

OJ Problem

[HR] AND product

Problem Statement

You will be given two integers A and B. You are required to compute the bitwise AND amongst all natural numbers lying between A and B, both inclusive. 108 more words

OJ Problem