Questions tagged [binary]
The binary tag has no usage guidance.
117 questions
2
votes
2
answers
120
views
Mathematica LinearSolve with additional constraints
I want to solve a linear Matrix equation over GF(2). I am currently using Mathematica's LinearSolve[A,B, Modulus->2] function to solve for X in the equation AX = ...
2
votes
1
answer
130
views
how to convert a decimal fractional number to binary with given number of digits after the binary point?
Given 0.4, the binary form is 0.0110011001(with 10 digits after ".") and 0.011001100110011001100110(with 24 digits after ".") without rounding.
Is there any function that can do ...
1
vote
0
answers
63
views
How to Parse Binary .STL File Created on Ancient 32-bit Architecture
Import[fileName,"STL"] returns $Failed
The file format is so simple that one can calculate the number of triangles in the file
by counting the number of BinaryReads to reach EndOfFile.
https:...
0
votes
1
answer
101
views
Binary algorithm for finding the range of elements
Consider a sorted list of real numbers listz and some boolean condition condition that involves these numbers:
...
0
votes
1
answer
65
views
Colorized hexdump
I have this hexdump command that I am writing to display a nicely printed hexdump into a mathematic grid. I want to be able to specify regions that I can highlight, however I am stuck being only able ...
1
vote
1
answer
192
views
How can I Xor two decimal numbers?
I want to take two numbers, say 200 and 101, and transform them into their binary form. Then XOR them together and transform the result back into the decimal form. The result in this case should be ...
1
vote
4
answers
2k
views
Converting two 8-bit integers into a single 16-bit integer
I have a situation where I have a pair of integers {a, b} where a and b are in bytes from a ...
2
votes
3
answers
182
views
How to calculate the rightmost 1 and the leftmost 1 in the binary representation of a large number x?
So I have an integer $x$ between $1$ and $2^{64}$ and I am looking for the fastest way to get the rightmost 1 (the least significant bit or LSB) and the leftmost 1 (the most significant bit, MSB). How ...
2
votes
1
answer
188
views
Parsing HTTP POST request or how to find a string in a byte array
I am a developer of a Mathematica web-server (see TinyWEB). I managed to parse a multipart POST request containing text files, however, it is hard to expand it to any types of binary data like JPEG, ...
5
votes
2
answers
188
views
DigitCount[], but in negative bases
The DigitCount[n,b] function "counts the gives a list of the numbers of $1, 2, \ldots, b-1, 0$ digits in the base-$b$ representation of $n$".
I want to ...
10
votes
3
answers
2k
views
Convert four bytes to IEEE 754 float
I have some bytes, say bytes=ByteArray@{189,178,61,188}, read from a file with Import[...,"Byte"]. The big endian ...
3
votes
1
answer
419
views
Convert List of integers to Hex
I'm doing some OpenCL computing with Mathematica, I have an SHA256 implementation running on my GPU. It returns a list of uints (64bit, Mathematica mistakenly treats these as signed 64bit ints), how ...
2
votes
1
answer
157
views
Importing IDL sav file into Mathematica
I have a rather big (around 400 MB) file written by the IDL (Interactive Data Language) software into its binary format ".SAV" which is a proprietary format, not the spss format expected by ...
9
votes
6
answers
225
views
Row function to join together binary number elements
I am trying to join entries of binary numbers at the lowest level of a nested list, e.g.
...
0
votes
0
answers
99
views
Real to IEEE 754 not working for values -1<x<1
I have written a Module that takes a real number and returns the IEEE 754 floating point binary equivalent. It works fine for values above |1|, but I cannot get it to work for inputs less than |1|.
<...
2
votes
1
answer
74
views
Changing values in a list
I am currently working the genetic algorithm, specifically in the mutations part, that takes binary numbers and want to convert some of the values in a string into another value.
For example,
...
2
votes
1
answer
117
views
Need help converting decimals to Binary
I am struggling figuring out how to turn decimals between {0,1} to binary. I am currently trying to use RealDigits[] and FromDigits[] For example using:
...
4
votes
2
answers
450
views
Numbers to binary and back
I am struggling on how to create a function that converts a number into binary and then back. I know there is a built-in function about this BaseForm[] but I am ...
0
votes
1
answer
642
views
Algorithm to convert real numbers decimal to binary
Currently trying to write code that converts decimal floats to binary base form (I know BaseForm exists).
Currently I'm working with an example that takes 3.3 and converts it:
...
1
vote
3
answers
113
views
Converting Binary Values to Points [closed]
I searched a lot for this question but couldn't find a similar question.
How can I convert my binary values to points. The output of the code I wrote is below, I wrote my expectation also below.
...
0
votes
1
answer
62
views
How do I get 3 digits binary after calling BaseForm or IntegerDigits [duplicate]
Let's say I have a list called 'solution', I'm converting these numbers into binary form
...
2
votes
1
answer
56
views
How to read doubles from specific location of a large file
I have a 1GB file in a proprietary format that is a mix of ASCII characters and doubles (floating point numbers). I need to read in a sequence of twelve doubles. They are in consecutive bytes of the ...
12
votes
3
answers
585
views
Generating a matrix with specific number of 1's in every row and column
I would like to have a function f(n,k) that generates a random nxn matrix with k elements equal to 1 in each row and column and has an all-zero diagonal, with all other elements equal to 0. In other ...
1
vote
1
answer
105
views
Extracting data from binary file without reading the whole file - is this possible? [duplicate]
Suppose I have a binary data file that holds 1 million lists each composed of five integers. i.e. $\{ x1,x2,x3,x4,x5 \}$
Perhaps I am missing something obvious (quite likely) - but if I know I want to ...
1
vote
0
answers
120
views
Implementing the Binary GCD algorithm in Mathematica
Well, I have $n\in\mathbb{N}$ and I want to transform $n$ to a binary number which can be done using FromDigits[IntegerDigits[n, 2]]. I want to compute the ...
4
votes
1
answer
277
views
Using Mathematica to derive analytic form of single variable function
I am interested in finding an analytical form of the following function $f(n)$ defined as:
$$f(n):=\sum_{\{\bar{K}\}}\prod_{l<j}^{n}e^{ik_lk_j},$$ where $\{\bar{K}\}$ is the full set of binary ...
2
votes
1
answer
148
views
How to separate these circle based on their pixels mean intensity?
I have this image I want to separate green circles from yellow circle in two different images whiteout changing the pixel intensity information. I used the mean intensity
...
4
votes
1
answer
129
views
Binary permutation list code in Mathematica
Given some natural number $N$, I am interested in the set of all binary permutations of length $N$ (with the intention of storing in lists depending on how many $1$'s appear in each permutation). My ...
1
vote
3
answers
272
views
Minimizing a function over a bounded domain with binary variables
I want to minimize the following function:
$$
f(m,n)= \sum_{i=1}^N\Big\{ \alpha_i(x_i-m)^T(x_i-m) \Big\} + \sum_{i=1}^N\Big\{\beta_i (x_i-n)^T(x_i-n) \Big\}
$$
where $m,n$ are all 2-d vectors:
$$
m:= ...
11
votes
1
answer
498
views
What is the relationship between the Wolfram executables? Where is this documented?
The relatively new wolframscript now accompanies the traditional math and wolfram binaries. ...
5
votes
1
answer
681
views
Read binary files and separate the 64-bit unsigned integers into certain forms?
I have a binary file where each data is a 64-bit unsigned integer (little endian). For simplicity, let's say the data in testdata.bin file opened in HxD is:
namely:...
2
votes
1
answer
551
views
How do I get the data from this binary file? [duplicate]
I have a file which contains the following binary data:
...
7
votes
1
answer
1k
views
Convert ByteArray to integer and real values
during the import of a complex file format I handle ByteArray or lists of byte values. While I can easy transform them from one type to each other:
...
4
votes
2
answers
199
views
How to generate the 8^th order symmetric binary matrices whose sum of absolute eigenvalues is 8?
It is needed to generate all 8th order(8 by 8) symmetric binary matrices(of 0's and 1's) such that the sum of the absolute eigenvalues is 8. Listing all the 8th order symmetric binary matrices and ...
0
votes
0
answers
40
views
FindClusters Hamming Distance giving error
I am trying to run FindClusters[hex, DistanceFunction -> HammingDistance[IntegerDigits[#, 2, 8], IntegerDigits[0, 2, 8]] &] over a list of data but I keep ...
0
votes
1
answer
105
views
Import and create a hexdump view of file
How would I go about creating a hexdump type of view of an imported binary file?
for example, (format is
...
1
vote
0
answers
47
views
Reading product of same ByteArrays
I am handling a huge set of data and I am trying to optimize my code. I have very large expressions to expand and simplify and I've seen that converting the expressions to ByteArrays improves a lot ...
4
votes
4
answers
303
views
Generating all symmetric binary matrices of order up to 7?
I want to create all symmetric binary matrix with order up to 7. Can anybody help in creating this?
I want to obtain the subset of all symmetric matrices, with all diagonal entries being zero.
2
votes
3
answers
258
views
Simplifying expressions containing binary variables
Consider an expression with two binary variables, $a,b\in\left\{ 0,1\right\} $, given by $F=(1-a-b)^{3}(1-b)$, with truth table:
...
1
vote
2
answers
80
views
FindMaximum under binary constrains
I'm trying to find a maximum for a function whose variables have binary values (either -1 or 1). The clumsy code for that constraint I use is shown below. There must be a more compact code, and I ...
0
votes
0
answers
50
views
Table Glitch / Error with binary data
I have a large group of binary files that I am loading with
binaryList = Table[ BinaryReadList[ paths[[i]], "Byte"], {i, Length@paths}];
specifically ...
1
vote
1
answer
438
views
Import OVF 2.0 Vector field files
I'm using a simulation software (mumax3) which outputs OVF_2.0 files. It can either export binary or text files. The binary files are usually much smaller than the text files. I would like to use the ...
11
votes
7
answers
3k
views
Find if there are consecutive 1s in a binary representation of a number
Given a list of numbers in decimal form, what is the most efficient way to determine if there are any consecutive 1s in the binary forms of those numbers? My solution so far:
...
1
vote
1
answer
269
views
Construct a binary tree where nodes are labeled according to given rule
I want to plot a binary tree in Mathematica where the nodes are labeled according to a given rule. In fact, whether a node has a left child or a right child or both, will be determined by a rule. And ...
1
vote
1
answer
102
views
How to understand and use bit operation for programming
I got the following code using bit operation from here:
...
6
votes
0
answers
143
views
Importing a 12 bit array
I have a binary file of 12 bits integers obtained from a camera software. It can produce FITS files from these but the processing time on the large data set I have is excessive. What I have is the ...
3
votes
0
answers
188
views
How to recover plaintext from .MX files?
I need a function to deserialize the contents of an MX source file for reading. We can’t simply use Get because I don’t want to load or run the code, but rather to ...
12
votes
0
answers
488
views
Why does Mathematica consume so much memory when reading binary data?
There are somewhat similar questions on here, but I didn't find a satisfying answer for this case: I import a 1.7 GB binary data file using the following command:
...
3
votes
1
answer
333
views
How to get the bit size (bit length) of an integer? [closed]
Suppose I have the integer 255, so 11111111 is its base 2 (bit) representation and the bit size of 255 is 8.
How can I calculate the bit size of a (big) integer in Mathematica?
Is there a built in ...
1
vote
1
answer
229
views
Why ImportByteArray when generate image from bytes
I was trying to generate an image from a list of bytes so I only had to Import an Image once as I want to store a Base64Encoded ...