# Tag Info

### Find if there are consecutive 1s in a binary representation of a number

Update: just use BitAnd[x, BitShiftRight[x, 1]] > 0. It's 10x faster than below. Bit-level parallelism beats multiple shifts every time. This method is super ...
• 25.6k
Accepted

...
• 9,498

### How to total the amount of zeros in a binary matrix

ClearAll[countZ] countZ = 1 ## & @@ Dimensions @ # - Total[#, 2] &; countZ@binarym 17 Timings: ...
• 399k
Accepted

### What is the relationship between the Wolfram executables? Where is this documented?

math/wolfram, MathKernel/WolframKernel are all the same: ...
• 236k
Accepted

### Find if there are consecutive 1s in a binary representation of a number

It seems like directly constructing the list might be the fastest method. Most numbers will have consecutive ones. Based on the wrap-around criteria, we already know that testing any odd number is a ...
• 10.1k

### Using Mathematica to derive analytic form of single variable function

If one makes a table of the first few values of $n$, then a pattern becomes evident: Table[{n, f[n]}, {n, 3, 8}] // TableForm One can see that the leading term is ...
• 42.2k

### BitNot does not flip bits in the way I expected

twosComplement[x_, n_] := UnitBox@IntegerDigits[x, 2, n] twosComplement[35, 8] {1, 1, 0, 1, 1, 1, 0, 1}
• 10.9k
Accepted

...
• 399k
Accepted

### Substitute some 1s with 0s in random list

Updated to include suggestions from comments My original idea, using BitAnd, switching $0\leftrightarrow1$, and multiplying. This idea uses 3 vectorized binary ...
• 131k

...
• 161k

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

LengthWhile[#, Positive] & /@ binarym {3, 4, 2, 4, 6} Or binarym /. {x : Longest[1 ..], __} :> Length[{x}]
• 82.2k
Accepted

### BitNot does not flip bits in the way I expected

I don't think there is a built-in function to generate the two's complement representation. Easy to implement though. ...
• 10.3k
Accepted

### Something is wrong with the implementation of the ThueMorse function

The problem is the following: Mod[Plus @@ IntegerDigits[n, 2], 2] Mod[2 + n, 2] This happens because ...
• 36.4k

### Find if there are consecutive 1s in a binary representation of a number

For the sake of getting answers for higher values of dim, I present to you some bit manipulation hacking for dim=20: ...
• 9,498

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

Update: ff works as is in version 9. For versions 10+, as commented by @Mr.Wizard, it needs to be modified to prevent the index i...
• 399k
Accepted

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

I will turn Kuba's comment into an answer. The EncryptedObject you create using Encrypt contains the encrypted data and the ...
• 1,159

### Generating a matrix with specific number of 1's in every row and column

My package IGraph/M has several functions for this. But before you get started, think carefully about what you mean by "random". I am going to assume that you want to generate each such ...
• 236k

### Convert four bytes to IEEE 754 float

As @DanielLichtblau points out, ImportByteArray is surprisingly slow. Here's a LibraryLink code that uses a bare-metal byte-to-float type cast. Its advantages are: ...
• 49.1k
Accepted

### How is the mysterious Raw function used?

The short answer is, you can't. The only function that can really consume these objects is not exposed at the language level but only in the kernel's own C code. To be honest, am not sure why it is ...
• 14.2k

### Substitute some 1s with 0s in random list

The following function is based on the Ramp and Differences functions, as suggested in a comment by @garej . Its speed and low ...
• 12.6k
Accepted

### Reading a file as a ByteArray?

Import[..., "String"] and Export[..., "String"] are meant precisely for this and will not cause problems. This is guaranteed to ...
• 236k

### How to get the bit size (bit length) of an integer?

You can use BitLength or IntegerLength: BitLength[number] 4091 ...
• 399k

### Row function to join together binary number elements

Let's define a function that joins together two of the entries: join[{x_, y_}] := ToExpression[StringJoin[{ToString[x], ToString[y]}]]; Now we can use this ...
• 69.5k

### Row function to join together binary number elements

Map[FromDigits @* Flatten @* IntegerDigits, testlist, {2}] ...
• 399k

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

First /@ SparseArray[1 - binarym]["MatrixColumns"] - 1 {3, 4, 2, 4, 6}
• 26.9k
Accepted

### Printing binary numbers with extra zeros

It's unclear in your question if you are asking for a String for NumberForm. FORM If you want to change the Form but not ...
• 36.9k

### BitNot does not flip bits in the way I expected

Without using IntegerDigits[]: ...

### Convert four bytes to IEEE 754 float

As shown already, this can be done by ImportByteArray. If you have long lists, this can be slow. Here is a test. ...
• 59.6k
Accepted

### DigitCount[], but in negative bases

Background mathworld.wolfram.com contains entries for Negabinary, Negadecimal and Base, including Wolfram language code examples Base $(-2)$ Negabinary ...
• 36.9k