Questions tagged [binary]

The tag has no usage guidance.

27
votes
3answers
3k views

Reading periodic elements from a large file

I have a large binary data file (big endian) with 100+ million "rows" of 11 elements, combination of floats and integers. This is the format: ...
22
votes
2answers
273 views

BitShiftRight produces incorrect results in Version 10

Bug introduced in 10.0.0 and fixed in 10.0.2 With Mathematica 10 for Mac, BitShiftRight works properly on lists of up to 100000 numbers, but appears to give ...
21
votes
1answer
757 views

Faster binary Hamming weight for big integers?

While working on an answer to Count the sequences in an array I found that DigitCount was the bottleneck in my code when used as ...
20
votes
6answers
2k views

Graph from binary matrix (not adjacency) respecting the original matrix positions

I have a binary matrix. My objective is to connect every close (without "jump") elements with value equal to 1, but I must keep the point positions, just like it's shown at the image. Can somebody ...
18
votes
2answers
2k views

Import Fortran unformatted binary

I have an unformatted binary file generated using the Compaq Visual Fortran compiler (big endian). Here's what the little bit of documentation states about it: The binary file is written in a ...
16
votes
1answer
465 views

How is the mysterious Raw function used?

I have never seen an example use for the mysterious Raw function: Raw[h, "hexstring"] constructs a raw data object with head h, and with contents ...
12
votes
1answer
2k views

How to read 32-bit *IBM* (not IEEE) floating point values from a binary file?

I am trying to read a binary file. This file records seismic data. Basically its first 3600 bytes are for the general file information, following are for seismic traces, each begins with 240 bytes for ...
10
votes
5answers
883 views

Substitute some 1s with 0s in random list

How is it better to substitute list of random combination of 1 and 0 (binary image) so that only first (or central) instance of 1 left in each group. ...
10
votes
1answer
183 views

Performance-driven approach to using Big Data without killing the hard-drive

Situation A calculation has to be done in which the amount of data is too much to fit into memory. Fortunately, only a part of the overall data set has to be known at a time. The preprocessing is ...
9
votes
8answers
579 views

How to find the sum for each individual row in a binary matrix until the first zero is reached from left to right.

I have a 150 by 300 binary matrix. I would like to sum the 1's for each individual row (from left to right) until the first zero is encountered. For example, if a given row is 1 1 1 1 1 1 0 0 0 1 0 0 ...
9
votes
2answers
626 views

How does Mathematica decide that Log[2,8] is integer?

At school we learned that $\log_b(x)=\log(x)/\log(b)$, which is implemented in Mathematica as Log[b, x], but the results are different. ...
9
votes
2answers
847 views

No builtin function for bitwise rotation?

There appears to be no builtin Mathematica function for bitwise rotation. Is that true? I suppose I can write my function: ...
7
votes
4answers
661 views

BitNot does not flip bits in the way I expected

Can anyone explain why the last result in these statements is not the bit-flipped version of arr? ...
7
votes
2answers
1k views

How to do binary calculation?

For example, $a=0.10101$ in binary representation. Then how to calculate $a^2$ directly in mathematica? Is there any function turning binary into decimal? I only found its inverse...
7
votes
3answers
303 views

Reading a file as a ByteArray?

I want to read in large files as byte strings. Import[..., "Byte"] yields a list of Integers that takes up much more space (16 times more) than the file. ...
7
votes
2answers
396 views

Infinite base two number to base ten

Suppose I have a base two number that repeats itself every five places (a number $x$ such that $0\le x<1$. For example: $$x=0.101011010110101101011010110101101011010110101...$$ What would be a ...
7
votes
1answer
335 views

HMAC implementation in pure Mathematica

I am trying to implement the HMAC algorithm in Mathematica. The algorithm is a relatively simple way of signing messages with a key. Here is some pseudocode from Wikipedia: My attempt: ...
6
votes
1answer
164 views

Is it possible to convert the output of the Encrypt[] function into binary digits?

I use the following code to generate a key and then use it to encrypt a simple string message. The output of the function Encrypt is an encrypted object. But I would rather convert this into binary ...
6
votes
1answer
461 views

How do I directly read the Nth byte from a binary file?

I have a very large binary file (several hundred GB) which I would like to process using Mathematica. I only need to process a few bytes of this file at a time, and I know in advance which bytes I ...
5
votes
5answers
2k views

All binary sequences with length n

I don't know if there is a built-in function for this, but I'm thinking about something like this Outer[List, Table[{0,1},{n}] ] But ...
5
votes
3answers
1k views

Is there a function for nearest power of 2 in Mathematica like nextpow2 in MATLAB?

I am looking for something like nextpow2 in MATLAB like this: P = nextpow2(A) returns the exponents for the smallest powers ...
5
votes
2answers
297 views

Printing binary numbers with extra zeros

I have the numbers $0-64$ in binary and want them all to be displayed with 8 figures. Expected output: $5_{10} = 101_2$ should become 00000101.
5
votes
1answer
177 views

Decoding GZIP encoded Body, BodyBytes (ByteArray) and BodyBytesArray from URLRead

When calling the Stack Exchange API v2.2 using the new (Mma11) function URLRead we get a GZIP encoded Body in alternative formats: ...
5
votes
0answers
70 views

How to force the writing of buffers onto disk?

Usually, buffering is good; except when you critically need to write data to disk. Is there a way to force the writing of buffers onto disk? (I'm using a binary file) I believe a ...
4
votes
4answers
697 views

How to total the amount of zeros in a binary matrix

I have a 150 by 300 binary matrix. I would like to find the total amount of zeros in the matrix. I've been consulting online documentation for support, but am unable to use the "count" function ...
4
votes
1answer
351 views

How to read this dataset with .dat and .r64 files?

I stumbled upon the European Data Incubator project, and wanted to play around with some of their data. I'm trying to open this dataset, which contains a bunch of ...
4
votes
1answer
631 views

Importing FITS file from HEALPix

I am trying to read FITS file created by HEALPix software. The file contains a spherical map of a scalar field. There is the online support on how to use the file in IDL, but not for Mathematica. I ...
4
votes
1answer
139 views

Importing binary structured C++ data file

I am trying to import a binary data file. It seems that BinaryReadList would be appropriate? However the data file is composed of c++ structures like this: ...
3
votes
4answers
1k views

Importing or reading data in binary format 212

I have a binary data file in format 212, and I want to import the file into Mathematica. How do I read or import binary format 212? I almost have no direct experience of working with any binary format....
3
votes
1answer
88 views

Something is wrong with the implementation of the ThueMorse function

While trying to answer this Math.SE question, I believe I found several bugs in Mathematica and Alpha relating to the Thue-Morse sequence. As a quick reminder, the $n^{\rm th}$ element of the Thue-...
3
votes
4answers
629 views

Simplify binary expressions

Is it possible for Mathematica to do simplifications for expressions where the variables are binary, such as: a + b = 1 + 2*c => a + b = 1 Here c must be 0 because if it is 1, the RHS is 3 but the ...
3
votes
1answer
135 views

updating matrix elements based on a condition

I am (still) fairly new to Mathematica and trying to perform some operation on the matrix elements, say for the matrix ...
3
votes
1answer
123 views

Convert characters to binary?

I can get a binary representation of characters as follows: BaseForm[ToCharacterCode["A"], 2] However, that produces a weird binary code object that might be ...
3
votes
1answer
710 views

Binary file gymnastics

I have an unformatted binary file generated by fortran 77 and i want to import it in Mathematica. The file is formed by 5 data arrays with double precission float numbers. The problem is that seems ...
3
votes
1answer
174 views

Binary decision diagrams (BDD) syntax error

I am new here (and to Mathematica) and would like to rebuild a simple binary decision diagram that I found here https://en.wikipedia.org/wiki/Binary_decision_diagram A code has been provided as part ...
3
votes
0answers
22 views

Does NumericArray always maintain data unmodified?

Suppose that we create a NumericArray using a LibraryLink function, then pass this to another one. Is NumericArray guaranteed to maintain the binary data as it was ...
3
votes
0answers
120 views

How to import a binary data generated by Fortran? [closed]

I have a unformatted binary data file generated by gfortran. However, when the binary data is imported by Mathematica, a correct result is not obtained. This is my fortran code: ...
2
votes
2answers
2k views

Doing arithmetic with binary numbers

How do I execute binary operations in Mathematica? I want to to multiply say 1010101011 (binary) to 1111101110 (binary) and getting the result 10100111101111111010? Then I want to add the result to ...
2
votes
4answers
189 views

Replacing High Densities of 1.s in Very Large Binary Arrays

I am working with very large binary arrays on the order of {100,100000}. It may look something like this. data = N[Table[RandomInteger[], {i, 100}, {j, 100000}]]; ...
2
votes
1answer
129 views

Generate a prime number in a range with fixed $n$ most significant bits

I'm new to Mathematica so my question might be trivial. How do I generate a $200-bit$ prime with the condition that the 10 most significant bits in its binary representation are equal to some binary ...
2
votes
1answer
85 views

Interpret hexadecimal sequence as a binary matrix that can be used in AdjacencyGraph

I have a database of hex sequences stored as blob. Each of them is a binary matrix representing the adjacency matrix of a directed graph. I want to use the ...
2
votes
1answer
217 views

BinaryWrite negative numbers [closed]

testList = {1, 2, 3, 4}; file = "test1"; BinaryWrite[file, testList]; BinaryReadList[file] Close[file]; Gives {1, 2, 3, 4} ...
2
votes
2answers
384 views

Generating b/w bitmaps from a binary sequence

I would like to make a bitmap that visually represents a binary sequence, something like this: Where for example the 1's become a black pixel and the 0's a white one. I have never done something ...
2
votes
2answers
91 views

Listing all monotone increasing binary digits

For $n=5$, I have $32$ binary digits and for this there are $2^{32}$ combinations. Out of this many, the interesting ones (i.e., the ones that have monotone increasing binary digits) are only about "$...
2
votes
1answer
66 views

Convert Negative Integers into Signed Binary?

I'm relatively new to Mathematica and have been struggling with this problem for several days. I have a string of integer data, ranging from -2044 to 2044. So this looks something like {-2044,-2040,-...
2
votes
1answer
89 views

Recurrence relation for multivariate polynomials

I am trying to define a function which recursively computes a polynomial associated to every binary string: ComputePoly[s_]:=(** Recurse on the string s**) For ...
2
votes
0answers
219 views

Converting hex string to ByteArray

With blockchain support, it should finally become straightforward to convert string hashes to ByteArray, but I still can't figure out the canonical Wolfram way of ...
1
vote
2answers
67 views

Number of contiguous ones of an element in a 2d binary array

I have a 2d binary array of 0s and 1s. I select an element and would like to know how many 1s are in the contiguous cluster that includes the selected point. If the selected element is 0, the answer ...
1
vote
2answers
91 views

Command to change binary mlf terms into Subscripted mlf terms?

I express multilinear functions in the following format. Is there any ready command to convert them to multilinear functions easily? Input ...
1
vote
2answers
833 views

Read a binary file to an image in memory then analyze it

Is it possible to read a whole file (~100 MBs) into memory, and then use BinaryRead[] function on the data loaded into memory to read/cast it to the types I need with a proper StreamPosition pointer? ...