Integer with reversed and inverted bits of n assuming bit length r.

    >>> reinverted(1, 6)
    31

    >>> [reinverted(x, 6) for x in [7, 11, 13, 14, 19, 21, 22, 25, 26, 28]]
    [7, 11, 19, 35, 13, 21, 37, 25, 41, 49]
358484
def reinverted(n, r):
    
    result = 0
    r = 1 << (r - 1)
    while n:
        if not n & 1:
            result |= r
        r >>= 1
        n >>= 1
    if r:
        result |= (r << 1) - 1
    return result
222854
def reverse(d):
    """"""
    r={}
    for k in d:
        r[d[k]]=k
    return r
948876
function initReversedBytes() {
	var i,
	    result = new Uint8Array( 0x100 );

	for ( i = 0; i < 0x100; i++ ) {
		result[ i ] = calcReverse( i );
	}

	return result;

	function calcReverse( original ) {
		var i,
			reverse = 0;

		for ( i = 7; i >= 0; i-- ) {
			reverse |= ( ( original & 1 ) << i );
			original >>>= 1;
		}

		return reverse;
	}
}
436867
def _number_of_set_bits(x):
    '''
    
    '''
    # Taken from http://stackoverflow.com/a/4912729. Many thanks!
    x -= (x >> 1) & 0x55555555
    x = ((x >> 2) & 0x33333333) + (x & 0x33333333)
    x = ((x >> 4) + x) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x0000003f
308644
function bnpChangeBit(n, op)
{
  var r = Int128.ONE.shiftLeft(n);
  this.bitwiseTo(r, op, r);
  return r;
}
1368719
def dec2bin(s):
    
    if not isinstance(s, int):
        num = int(s)
    else:
        num = s
    mid = []
    while True:
        if num == 0:
            break
        num, rem = divmod(num, 2)
        mid.append(base[rem])

    return ''.join([str(x) for x in mid[::-1]])
302468
def base26int(s, _start=1 - ord('A')):
    
    return sum((_start + ord(c)) * 26**i for i, c in enumerate(reversed(s)))
21368
function nbits(x) {
	var n = 1, t;
	if ((t = x >>> 16) != 0) {
		x = t;
		n += 16;
	}
	if ((t = x >> 8) != 0) {
		x = t;
		n += 8;
	}
	if ((t = x >> 4) != 0) {
		x = t;
		n += 4;
	}
	if ((t = x >> 2) != 0) {
		x = t;
		n += 2;
	}
	if ((t = x >> 1) != 0) {
		x = t;
		n += 1;
	}
	return n;
}
1368670
def bit_flip_operators(p):
    
    k0 = np.sqrt(1 - p) * I
    k1 = np.sqrt(p) * X
    return k0, k1
1129816
function (m, n) {
      n %= 64
      if (n === 0) {
        return m
      } else if (n < 32) {
        return [(m[0] << n) | (m[1] >>> (32 - n)), m[1] << n]
      } else {
        return [m[1] << (n - 32), 0]
      }
    }
696343
def lazy_reverse_binmap(f, xs):
    
    return (f(y, x) for x, y in zip(xs, xs[1:]))
812627
function reverse(a) {
  var len = a.length;
  for (var i = 0; i < Math.floor(len/2); i++) {
    [a[i], a[len-i-1]] = [a[len-i-1], a[i]];
  }
  return a;
}
635814
public static void reverseBits(byte[] b) {
        for (int k = 0; k < b.length; ++k)
            b[k] = flipTable[b[k] & 0xff];
    }
1097303
def reversal_circuit(qubits: Qubits) -> Circuit:
    """"""
    N = len(qubits)
    circ = Circuit()
    for n in range(N // 2):
        circ += SWAP(qubits[n], qubits[N-1-n])
    return circ
203477
function read_bits_n(buf, bl, n) {
	var w = (bl&7), h = (bl>>>3), f = ((1<<n)-1);
	var v = buf[h] >>> w;
	if(n < 8 - w) return v & f;
	v |= buf[h+1]<<(8-w);
	if(n < 16 - w) return v & f;
	v |= buf[h+2]<<(16-w);
	if(n < 24 - w) return v & f;
	v |= buf[h+3]<<(24-w);
	return v & f;
}
1203284
def bitlist_to_int(bitlist):
    

    ret = 0
    for b in bitlist:
        ret = (ret << 1) | (int(b) & 1)
    return ret
324352
function inverseMod_(x, n) {
  var k=1+2*Math.max(x.length, n.length);

  if (!(x[0]&1)  && !(n[0]&1)) {  //if both inputs are even, then inverse doesn't exist
    copyInt_(x, 0);
    return 0;
  }

  if (eg_u.length!=k) {
    eg_u=new Array(k);
    eg_v=new Array(k);
    eg_A=new Array(k);
    eg_B=new Array(k);
    eg_C=new Array(k);
    eg_D=new Array(k);
  }

  copy_(eg_u, x);
  copy_(eg_v, n);
  copyInt_(eg_A, 1);
  copyInt_(eg_B, 0);
  copyInt_(eg_C, 0);
  copyInt_(eg_D, 1);
  for (;;) {
    while (!(eg_u[0]&1)) {  //while eg_u is even
      halve_(eg_u);
      if (!(eg_A[0]&1) && !(eg_B[0]&1)) { //if eg_A==eg_B==0 mod 2
        halve_(eg_A);
        halve_(eg_B);
      } else {
        add_(eg_A, n);  halve_(eg_A);
        sub_(eg_B, x);  halve_(eg_B);
      }
    }

    while (!(eg_v[0]&1)) {  //while eg_v is even
      halve_(eg_v);
      if (!(eg_C[0]&1) && !(eg_D[0]&1)) { //if eg_C==eg_D==0 mod 2
        halve_(eg_C);
        halve_(eg_D);
      } else {
        add_(eg_C, n);  halve_(eg_C);
        sub_(eg_D, x);  halve_(eg_D);
      }
    }

    if (!greater(eg_v, eg_u)) { //eg_v <= eg_u
      sub_(eg_u, eg_v);
      sub_(eg_A, eg_C);
      sub_(eg_B, eg_D);
    } else {                   //eg_v > eg_u
      sub_(eg_v, eg_u);
      sub_(eg_C, eg_A);
      sub_(eg_D, eg_B);
    }

    if (equalsInt(eg_u, 0)) {
      while (negative(eg_C)) //make sure answer is nonnegative
        add_(eg_C, n);
      copy_(x, eg_C);

      if (!equalsInt(eg_v, 1)) { //if GCD_(x,n)!=1, then there is no inverse
        copyInt_(x, 0);
        return 0;
      }
      return 1;
    }
  }
}