141 questions
5
votes
2
answers
101
views
How do I decode a bit string representing a n-digit number, where the 'n' digits were grouped and encoded in bit words of different lengths?
Background
I am trying to decode a bitstring from a QR-Code, where the data was encoded in numeric mode. According to this QR-Code tutorial: https://www.thonky.com/qr-code-tutorial/numeric-mode-...
1
vote
0
answers
85
views
ProVerif error : bitstring comparison and type mismatch in XOR function
I'm using ProVerif 2.05 for modeling cryptographic protocols, but I'm running into errors when performing bitwise operations with the XOR function.
The error tells me that I have a type mismatch when ...
2
votes
3
answers
135
views
Bounds checking a float from only an unsigned bit string
I am trying to return the result of casting a single precision float to an int just from its bit string. I correctly grab the sign bit, exponent and mantissa from the bit string but I am unsure how to ...
-1
votes
1
answer
190
views
Determine whether you can reach bitstring B from bitstring A using specific operations
The question is, given two bitstrings A and B, determine whether you can reach B from A using the following operation:
Choose two indices i,j such that the values at both indices are the same, and the ...
2
votes
1
answer
503
views
Convert a binary string of 0s and 1s to a bitstring in elixir
Given a string such as "0110", how do I convert this to a bitstring containing the binary values represented by the string?
I checked the Base module, but it's based on RFC 4648 and is not ...
-2
votes
1
answer
70
views
using 8-bit binary response of a hardware
I have a piece of hardware that for instance returns the "response" below. Per the instructions, I would like to separate the response to the 1st and last 4 bits. But the lower bit response ...
2
votes
1
answer
47
views
Why is the first argument of child's constructor being used in parent's constructer when inheriting `bitstring.BitArray`?
I want my class to inherit the BitArray class but I'm running into a problem in the constructors. I have several positional and keyword arguments I want to use in the child but the first positional ...
2
votes
2
answers
195
views
Python efficient assigning of even and odd bits to a bitstring/bit_array
I receive serialized DDR data from a setup with 8 chips. Due to the way the readout is implemented in hardware, the data that is received by the computer has the following structure:
bits 0 and 1 of ...
1
vote
2
answers
1k
views
How can I convert a bitstring to the binary form in Julia
I am using bitstring to perform an xor operation on the ith bit of a string:
string = bitstring(string ⊻ 1 <<i)
However the result will be a string, so I cannot continue with other i.
So I want ...
2
votes
4
answers
540
views
Nonzero for integers
My problem is as follows. I am generating a random bitstring of size n, and need to iterate over the indices for which the random bit is 1. For example, if my random bitstring ends up being 00101, I ...
1
vote
0
answers
36
views
Modified Zeckendorf represention
Given x as searched integer and k as minimum zeros between 2 ones.
Example:
x := 7,k := 0
Binary represention: 111
x := 7,k := 1
Binary represention: 1010
x := 7,k := ?(>1)
Binary represention: ?
...
0
votes
0
answers
48
views
how to find identical bitposition in a string in python
create a circuit of 5 qubits
qr = QuantumRegister(5, "qr") # quantum bit register
cr = ClassicalRegister(5, "cr") # classical bit register
circuit = QuantumCircuit(qr, cr)
# all ...
1
vote
0
answers
43
views
How to find identical bitposition in a string?
I have created a sequence of bitstring. Now I want to calculate the identical bit positions all sequences one by one.
I don't understand how to find it.
S1: ...
1
vote
0
answers
3k
views
How to import already installed python module "bitstring"
I'm on Windows and working on a python file from a cloned gitHub repository. When trying to do
import bitstring as bs
I get this error:
ModuleNotFoundError: No module named 'bitstring'
But "pip ...
0
votes
1
answer
444
views
How do I turn a file into a RAW bitstring?
How do I read a file and turn it to a RAW bit string? For example I open an image that is 512kb, It reads the file byte by byte, and it spits out the long bit string that is the file? I would like to ...
0
votes
2
answers
346
views
Randomly Generate bitstrings with fixed sum
I would like to generate a set of randomly generated bit strings with a certain length N, but I would like to ensure that the sum of each bit string adds up to a certain number, say $k$. How would I ...
5
votes
1
answer
151
views
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 ...
1
vote
2
answers
327
views
Pack data, extreme Bitpacking in Python
I need to pack information as closely as possible into a bitstream.
I have variables with a different number of distinct states:
Number_of_states=[3,5,129,15,6,2]# A bit longer in reality
The best ...
2
votes
0
answers
107
views
Compression algorithms based on bit-strings that are very simple to implement?
Given the type of bitstrings in Haskell:
data Bits = O Bits | I Bits | Nil
Are there compression algorithms that have satisfactory results (specially when it comes to repeated substrings), that are ...
1
vote
3
answers
760
views
Pattern matching a bitstring using pin operator in Elixir
# Erlang/OTP 24, Elixir 1.12.3
bmp_signature = <<66, 77>>
#=> "BM"
<<^bmp_signature, _::binary>> = <<66, 77, 30, 0>>
#=> ** (MatchError) no match ...
0
votes
1
answer
301
views
Write/read bit-string to/from a file
I've encoded an 8x8 block of numbers using RLE and got this string of bits that I need to write to a file. The last coefficient of the sequence is padded accordingly so that the whole thing is ...
2
votes
1
answer
77
views
Having Trouble converting a string to bytes
I'm trying to convert a string to a byte, thats what I've done.
I want to send out a Modbusprotocol via serial and put it together in bitstring:
tiger = '01'
read = '03'
ac_val = '0031'
word = '0002'
...
0
votes
0
answers
159
views
How succint bitvectors in C++ has so low memory usage
I am working with bitsets std::bitset<29621645> (i.e. with sizes of 29621645 bits) in C++. Each bitset fills around 29MB, which is a lot.
I fell over a library called sdsl which have their own ...
2
votes
1
answer
71
views
What happens when there is a NOT (~) on a bit shift operation
Just looking for some clarification on this homework question
The bitshift operation is ((1010 & ~(1 << 3))
So it's a left shift by 3 which would then be 0000, but with a the not, would it ...
0
votes
2
answers
473
views
Writing bitstrings to a binary file in C++
I am working on a compressor which compresses text files using Huffman coding in C++. After I perform the encoding, I get a bitstring(assume arbitrary length or say length = 2611) which represents the ...
0
votes
1
answer
2k
views
How to convert a Byte to a Bitstring in Kotlin?
I have an ArrayList of Bytes. Firstly, when i print them i see integers? And the second thing is, i want to convert each Byte to a Bitstring and add it to a new list of bitstrings. How do i do that as ...
1
vote
1
answer
2k
views
Writing bits (from a bit string) to create a binary file in python
I am new to python. Here is what I am struggling to implement.
I have a very long bit string "1010101010101011111010101010111100001101010101011 ... ".
I want to write this as bits and create a binary ...
1
vote
3
answers
1k
views
Bitwise operations on byte string and int
i am in the process of converting some cython code to python, and it went well until i came to the bitwise operations. Here is a snippet of the code:
in_buf_word = b'\xff\xff\xff\xff\x00'
bits = 8
...
0
votes
1
answer
2k
views
How can i convert a BitString into a String in Elixir?
I have a function that receives a list of strings and concatenates each string into a new string, i do that using Enum.join. But when i try this operation, i get the following error:
** (Protocol....
4
votes
7
answers
5k
views
python bytes to bit string
I have value of the type bytes that need to be converted to BIT STRING
bytes_val = (b'\x80\x00', 14)
the bytes in index zero need to be converted to bit string of length as indicated by the second ...
0
votes
1
answer
152
views
Return array of bitstrings after generating instead of just printing
This is the code from geeksforgeeks which generates and print bitstrings of n bits but I want to know instead of printing the array, how can I store the values of the array or return it so I can use ...
0
votes
2
answers
184
views
Creating a OssBitString from a std::string?
The OssBitString takes in string length (in bits) and a const unsigned char* as parameters. However, when I convert the input std::string to const unsigned char* and pass it to OssBitString, the ...
0
votes
0
answers
97
views
How to convert a normal std::string to OssBitString?
The OssBitString takes in string length (in bits) and a const unsigned char* as parameters. However, when I convert the input std::string to const unsigned char* and pass it to OssBitString, the ...
0
votes
1
answer
257
views
Bit-string without consecutive 1's, using Top-down DP
count all distinct binary strings without two consecutive 1's
I tried to convert bottom-to-top dynamic programming approach(mentioned in the link) to recursive relation but could not able to get the ...
2
votes
1
answer
1k
views
How does encoding as a bit string in Genetic algorithm helpful?
Suppose we have to solve a global optimization problem in which we have to find values of 5 variables, all of which are integers. Assume we get following two parent chromosomes,
Parent 1: 6, 10, 3, 5,...
1
vote
1
answer
292
views
Changing the indexing order of BitArray in Python
I am using a BitArray in my python script, and I was wondering if there is a way to change the indexes order of the BitArray that I create. Right now the indexes are from 0 to N-1 where N is the ...
0
votes
1
answer
674
views
Binary representation of complex numbers with bitstring in python
I have a file with text and binary. Text is used to identify beginning and end of a chunk of binary data, which represents a list of complex numbers, e.g. (1.5+5.6j)(...).
I have implemented the ...
0
votes
0
answers
112
views
Parsing specific strings from binary files
I need to process all binary files(PE32) from a folder.
I'm looking to extract a specific string from each of these executables.
The strings are sometimes found in little-endian, in some files they ...
5
votes
2
answers
548
views
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(...
0
votes
0
answers
204
views
How can I copy byte parts from a bytearray?
I took a String e.g. "hello" and made it a byte array (str.getBytes()), now I want to take a selection of bits e.g. 5,17,26,...(up to 4 bytes/32 bits) of the byte array made of 8 bit bytes and ...
2
votes
3
answers
2k
views
How to write binary file with bit length not a multiple of 8 in Python?
I'm working on a tool generates dummy binary files for a project. We have a spec that describes the real binary files, which are created from a stream of values with various bit lengths. I use input ...
0
votes
1
answer
2k
views
16 bit artimatic sum in Python
I am working on a program that is creating IRIG106 Chapter 10 data for a cube-sat project. Currently it is being implemented in python and I am having difficulty implementing the final component of ...
0
votes
2
answers
4k
views
Don't understand why this "OverflowError: Python int too large to convert to C long" exception occurs
This code accepts a bitstring and converts it to a character string. The bitstring comes from a txt file that's read into the client, converted to bitstring then sent to the server.
def getChar(...
-1
votes
1
answer
1k
views
Python: ValueError: invalid literal for int() with base 2: '1001001 1101101 ...."
My XOR accepts two bitstrings and returns the XOR value of those two strings. I don't think the getXor function is reading the bitstring as integers and I've tried making changes but I'm not certain ...
3
votes
1
answer
277
views
Bijection between (n choose k) and bitstrings of length n with k bits set
While I know how to generate all (n choose k) bitstrings of size n with exactly k bits set to one, I'm struggling finding a bijection, that gets as input a number i between 1 and (n choose k) and ...
0
votes
1
answer
2k
views
Decoding a bitString using Huffman code table Java
The goal is to convert a bitString into a plain text using Huffman code table,
r=000
h=001
o=01
w=100
d=1010
e=1011
l=11
I stored the Huffman code table in two different String[] arrays:
String[] ...
0
votes
1
answer
912
views
send bitstring through serial port
I have been trying to figure out how to send a bitstring through python 3 using the serial module. Initially when I tried to serial.write it, it was sending the ascii code for 1 and 0. I'm new to ...
0
votes
1
answer
3k
views
What's the best way to flip a single bit in a bitstring?
Say for instance, you have an 8-character string representing an 8-bit byte; i.e '00000000' (0) and you want to flip a single bit, to make it '00010000' (16). What's the best or most elegant way to ...
1
vote
2
answers
703
views
Rendering bitstring from phoenix view
I have a bitstring of the form bitstring = <<18::6,8::4,2::5,16::5,18::6,3000::16,0::4>>. I want to render but poison or Jason doesn't seem to be rendering. What is the best way to render ...
1
vote
0
answers
1k
views
Float number to 32 bits IEEE754 single precision is 64 bits [duplicate]
When using this code
import bitstring
f = 1.0e+00
b = bitstring.pack('>d', f)
b.bin
I get 64 bits
001111111111000000000000000000000000000000000000000000000000000
But I need to get Float (IEEE754 ...