-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbitstringutils.py
More file actions
41 lines (30 loc) · 1.21 KB
/
Copy pathbitstringutils.py
File metadata and controls
41 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
bitstringutils.py - A few functions for operating on Bitstring objects.
See bitstring.py
"""
__license__ = """
GPL Version 3
Copyright (2014) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000, there is a non-exclusive license for use of this
work by or on behalf of the U.S. Government. Export of this program
may require a license from the United States Government.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
__version__ = "1.2"
__author__ = "Ryan Helinski and Mitch Martin"
import bitstring
def hd (a, b):
return (a ^ b).count(1)
def hw (a):
return a.count(1)
def as_ints(bits):
return bits.unpack(fmt='bin:%d' % len(bits))[0]