1#!/usr/bin/env python 2# 3# Copyright 2014 Free Software Foundation, Inc. 4# 5# This file is part of GNU Radio 6# 7# GNU Radio is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 3, or (at your option) 10# any later version. 11# 12# GNU Radio is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with GNU Radio; see the file COPYING. If not, write to 19# the Free Software Foundation, Inc., 51 Franklin Street, 20# Boston, MA 02110-1301, USA. 21# 22 23from __future__ import division 24from __future__ import unicode_literals 25 26 27 28def bitreverse(mint): 29 res = 0; 30 while mint != 0: 31 res = res << 1; 32 res += mint & 1; 33 mint = mint >> 1; 34 return res; 35 36const_lut = [2]; 37specinvert_lut = [[0, 2, 1, 3]]; 38 39def bitflip(mint, bitflip_lut, index, csize): 40 res = 0; 41 cnt = 0; 42 mask = (1 << const_lut[index]) - 1; 43 while (cnt < csize): 44 res += (bitflip_lut[(mint >> cnt) & (mask)]) << cnt; 45 cnt += const_lut[index]; 46 return res; 47 48 49def read_bitlist(bitlist): 50 res = 0; 51 for i in range(len(bitlist)): 52 if int(bitlist[i]) == 1: 53 res += 1 << (len(bitlist) - i - 1); 54 return res; 55 56 57def read_big_bitlist(bitlist): 58 ret = [] 59 for j in range(0, len(bitlist) / 64): 60 res = 0; 61 for i in range(0, 64): 62 if int(bitlist[j*64+i]) == 1: 63 res += 1 << (64 - i - 1); 64 ret.append(res); 65 res = 0; 66 j = 0; 67 for i in range(len(bitlist)%64): 68 if int(bitlist[len(ret)*64+i]) == 1: 69 res += 1 << (64 - j - 1); 70 j += 1; 71 ret.append(res); 72 return ret; 73 74def generate_symmetries(symlist): 75 retlist = [] 76 if len(symlist) == 1: 77 for i in range(len(symlist[0])): 78 retlist.append(symlist[0][i:] + symlist[0][0:i]); 79 invlist = symlist[0]; 80 for i in range(1, len(symlist[0]) / 2): 81 invlist[i] = symlist[0][i + len(symlist[0]) / 2]; 82 invlist[i + len(symlist[0]) / 2] = symlist[0][i]; 83 for i in range(len(symlist[0])): 84 retlist.append(symlist[0][i:] + symlist[0][0:i]); 85 return retlist; 86