Python module for handling binary data. It offers methods for creating, parsing and editing binary representations of various data types.
Questions tagged [bitstring]
137 questions
19
votes
5 answers
Convert binary (0|1) numpy to integer or binary-string?
Is there a shortcut to Convert binary (0|1) numpy array to integer or binary-string ?
F.e.
b = np.array([0,0,0,0,0,1,0,1])
=> b is 5
np.packbits(b)
works but only for 8 bit values ..if the numpy is 9 or more elements it generates 2 or more…

sten
- 7,028
- 9
- 41
- 63
14
votes
9 answers
Calculating Hamming weight efficiently in matlab
Given a MATLAB uint32 to be interpreted as a bit string, what is an efficient and concise way of counting how many nonzero bits are in the string?
I have a working, naive approach which loops over the bits, but that's too slow for my needs. (A…

nsanders
- 12,250
- 2
- 40
- 47
12
votes
2 answers
Slow bitwise operations
I am working on a Python library that performs a lot of bitwise operations on long bit strings, and I want to find a bit string type that will maximize its speed. I have tried the built-in Python int type, numpy, bitstring, and bitarray, and…

hosford42
- 376
- 2
- 16
12
votes
5 answers
Elixir/Erlang split bitstring on newlines?
Is there a way to split a bitstring loaded from a file on newlines? I have something like this:
A line of text
Additional line of text
And another line
And I want an array like this:
["A line of text",
"Additional line of text",
"And another…

Stratus3D
- 4,648
- 4
- 35
- 67
10
votes
2 answers
Erlang pattern matching bitstrings
I'm writing code to decode messages from a binary protocol. Each message type is assigned a 1 byte type identifier and each message carries this type id. Messages all start with a common header consisting of 5 fields. My API is…

mpm
- 1,066
- 9
- 23
9
votes
4 answers
append pandas dataframe automatically cast as float but want int
How do I get pandas to append an integer and keep the integer data type? I realize I can df.test.astype(int) to the entire column after I have put in the data but if I can do it at the time I'm appending the data it seems like that would be a better…

kaminsknator
- 1,135
- 3
- 15
- 26
9
votes
3 answers
Convert Bitstring (String of 1 and 0s) to numpy array
I have a pandas Dataframe containing 1 columns which contains a string of bits eg.'100100101'. i want to convert this string into an numpy array.
How can I do that?
EDIT:
Using
features = df.bit.apply(lambda x:…

beginner_
- 7,230
- 18
- 70
- 127
9
votes
2 answers
What is the difference between a Binary and a Bitstring in Erlang?
In the Erlang shell, I can do the following:
A = 300.
300
<>.
<<0, 0, 1, 44>>
But when I try the following:
B = term_to_binary({300}).
<<131,104,1,98,0,0,1,44>>
<>
** exception error: bad argument
<>
**…

quanticle
- 4,872
- 6
- 32
- 42
6
votes
2 answers
Bit-Count or Hamming-weight of a BitString in Elixir?
Please how can we efficiently calculate the hamming-weight of a bit-string in elixir?
Example: 0b0101101001 has a Hamming-weight of 5 (i.e. 5 bits set)
My Attempt:
iex> Enum.count(Integer.to_char_list(n,2),&(&1===49))

Charles Okwuagwu
- 10,538
- 16
- 87
- 157
6
votes
3 answers
Elixir one function to convert both floats and integers to bitstrings?
Does Elixir have a function that accepts integers and floats and converts them to strings?
I need something like this:
a = 3
b = 3.14
number_to_binary(a)
% => "3"
number_to_binary(b)
% => "3.14"
Is there a function in Elixir that already does…

Stratus3D
- 4,648
- 4
- 35
- 67
6
votes
2 answers
How to read complete file with bitstring
I want to read as many 24 bit chunks as possible from a file.
How can I do this using bitstrings' ConstBitStream
when I don't now how many chunks there are?
Currently I do this:
eventList = ConstBitStream(filename = 'events.dat')
for i in…

HWende
- 1,705
- 4
- 18
- 30
5
votes
3 answers
Measuring efficiency of Huffman coding with Python bitstring
I have the following string that I would like to Huffman-encode and store efficiently into a bit array:
>>> print sequence
GTCAGGACAAGAAAGACAANTCCAATTNACATTATG|
The frequencies of the symbols in sequence are:
>>> print…

Alex Reynolds
- 95,983
- 54
- 240
- 345
5
votes
1 answer
Can we construct an infinite list that satisfies a given bit predicate?
If we have a given predicate p :: [Bool] -> Bool that take an infinite list as parameter and return True or False based on some unknown conditions, and we have no idea what this predicate is.
Can we work out a function f :: ([Bool] -> Bool) ->…

lucas
- 53
- 3
5
votes
2 answers
Make maximum 1's by flipping k bits at a time
Given an n-bit vector and an integer k, 1 <= k <= n, we have to maximize the number of ones in it by applying the following operation any number of times(including zero):
Choose exactly k bits(not necessarily continuous) and flip their state (0 to…

Manish Chandra Joshi
- 431
- 2
- 11
5
votes
2 answers
Convert Bit String To Array in PostgreSQL
I have a 160 chars bit string and I need to have an integer array that stores the position of the bits that have a value of 1.
Example:
bitstring = '00110101'
array = [3,4,6,8]
Is it possible to do this just with SQL or do I need to define a PL/SQL…

Topo
- 4,783
- 9
- 48
- 70