Questions tagged [binary]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
41 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 ...
3
votes
0answers
28 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
1answer
110 views

Read NumericArray from a file

Suppose I have a binary file which consists of a list of integer or real numbers. Let's say signed 8-bit integers; so each byte of the file is a single such integer. How can I read it and turn it into ...
3
votes
1answer
89 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-...
7
votes
4answers
673 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? ...
3
votes
0answers
134 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
93 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 "$...
1
vote
2answers
68 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 ...
0
votes
1answer
252 views

Using the binary search algorithm in a sorted grid

I want to get a mathematica code for binary search algorithm applied to a sorted grid containing integers. For example, given f[k_,x_]= x^2 + k x + k - 2 where <...
4
votes
1answer
411 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 ...
2
votes
0answers
234 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 ...
2
votes
1answer
133 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 ...
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 ...
1
vote
0answers
54 views

Efficiently transform sequentially generated integer matrices into boolean matrices

Assume you have a list of 5 numbers, eg L = {14, 7, 11, 14, 0};. Now, what you want to do with this list, is to transform each entry into eg a binary list, using <...
6
votes
1answer
167 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 ...
1
vote
0answers
160 views

The binary of negative integer number

I have a question about the binary of negative integer number in Mathematica. In most implementations, negative signed integers are stored in what is called two's complement. The other major way of ...
2
votes
1answer
69 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,-...
3
votes
1answer
138 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 ...
9
votes
8answers
581 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 ...
10
votes
5answers
887 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. ...
5
votes
2answers
299 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.
1
vote
0answers
39 views

Binary Image Size after import

I have a lot of binary images I would like to import into mathematica. Each of them is 132kB (1024x1024) big. Like the following: As soon as I import it into Mathematica however and call ByteCount[...
1
vote
0answers
50 views

Export 1bit Image

I have a binary image like the following one: How can I export it as an 1bit image instead of an 8bit one? If I export it in tiff it automatically becomes an 8bit one. Best, Max
0
votes
5answers
109 views

How to find all binary numbers with the kth =0 and smaller than 2^n?

I have been stuck in this problem for a long time. I need to find a general code to collect all binary numbers which are at most n digits (<2^(n-1)) with the ...
5
votes
1answer
197 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: ...
10
votes
1answer
194 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 ...
1
vote
1answer
118 views

Generate a list of randomly distributed $1$s and $0$s with fixed proportion of $1$s [duplicate]

I need to simulate a random initial state of an 1D cellular automaton, but with different 'densities' of filled cells. Let's say the size of the list is $N$, then I need to be able to fix a number $P$...
7
votes
3answers
319 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. ...
1
vote
0answers
114 views

How can I import Real16 binary data? BinaryReadList doesn't work [closed]

How can I import Real16 binary data? BinaryReadList doesn't work: ...
-1
votes
1answer
94 views

Turn binary number into string of words [closed]

I don't actually have any code for this, as I have no real idea how to do it. I have a large binary number combination that I know turns into some sort of string. How would I go about translating it?
1
vote
1answer
353 views

How to visualize .data files? [closed]

I am working with simulation models trying to carrying out some predictions in ocean waves and this stuff. (MITgcm) I am able to run the program and generate hundreds of .data and .meta files, but i ...
1
vote
2answers
86 views

How to replace the selected value in matrix with a specific digit?

I want to replace the selected values through "RandomChoice" by 1 and all other values in matrix with 0. I want output in binary form matirx. ...
6
votes
1answer
484 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 ...
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 ...
3
votes
1answer
178 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 ...
2
votes
1answer
86 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 ...
7
votes
1answer
341 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: ...
4
votes
1answer
143 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
1answer
139 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 ...
0
votes
1answer
38 views

How can I apply a matrix 2*2 to binary digits? [closed]

I want to apply a matrix 2*2 to a binary digits. For example, D and E are two matrices that they apply to a 1 and 0. D --> 1 & E --> 0 binary digits: (1011) --> D.E.D.D
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...
2
votes
1answer
231 views

BinaryWrite negative numbers [closed]

testList = {1, 2, 3, 4}; file = "test1"; BinaryWrite[file, testList]; BinaryReadList[file] Close[file]; Gives {1, 2, 3, 4} ...
21
votes
1answer
776 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 ...
2
votes
1answer
90 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 ...
0
votes
2answers
102 views

Troubleshooting Program Meant to Swap Elements

I wrote a program that is supposed to take a list (of arbitrary length) of pairs of the digits of binary numbers (e.g. ...
3
votes
1answer
743 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 ...
5
votes
0answers
71 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 ...
2
votes
2answers
400 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 ...
0
votes
1answer
167 views

Built in function to convert list of numbers into list of binary numbers [closed]

Does Mathematica have a build in way to convert a list of numbers into a list of binary numbers? If not how can this be accomplished?
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 ...