Showing posts with label binary. Show all posts
Showing posts with label binary. Show all posts

Monday, 2 November 2026

Binary Display

I noticed that Numbers Aplenty had the display shown in Figure 1 as part of its output for the number associated with my diurnal age today (28337) with the comment that "when arranged in a rectangular grid, its binary digits exhibit some kind of symmetry". The binary digits are 110111010110001 and there are 15 of them so they can be arranged in a 5 x 3 grid.


Figure 1

I quite liked this output and decided to incorporate it into the program for my daily number analysis. The output is as shown in Figure 2.


Figure 2

Every day, from this day forwards, there will be a similar display and I can decide whether there is anything of interest regarding the display, symmetrical or otherwise. Figure 3 shows the results for 27334 where there is also lateral symmetry.


Figure 3

The range of numbers for which there are 15 binary digits is 16,384 to 32,767 corresponding to \(2^{14}\) and \(2^{15}-1\). Prior to 16384, there is a range of numbers with 14 binary digits that can also be arranged in a rectangular grid. This range is from 8192 to 16383 corresponding to \(2^{13}\) and \(2^{14}-1\). Figure 4 shows the display for 16382:


Figure 4

Above 32767, we enter the realm of 16 binary digits and no grid will be displayed. The output for 32768 would be:

Integer : 32768
Binary  : 1000000000000000
Length  : 16 binary digits

Result  : Bit length 16 (factorization: 2^4) is NOT a biprime. 

No grid generated.

Of course, a 4 x 4 or 8 x 2 grid could be generated with a tweak of the algorithm but I'll consider that as I approach 32768 by which point I'll be 89 years old.

Saturday, 22 November 2025

The Secret Language of Numbers


This is a video generated by NotebookLM from two posts taken from this blogsite (Mathematical Meanderings). The posts are The Fibonacci Number Base from the 30th July 2019 and Zeckendorf Representation Revisited from the 14th April 2023. Here is the link but I've also embedded the video above. I'm quite pleased with the quality of the video, which is the third now that I've created using NotebookLM. The title for the video was proposed by the AI and I've gone along with it.

The whole process is just so quick and easy. You download the post or posts as PDF files and then upload them to NotebookLM. I have a dedicated notebook to which I upload the PDF files. There are several files there already that were used in previous videos. These files are deselected as sources and only the two latest files are selected. I go to video overview and get NotebookLM to generate the video and then download this as a mp4 file and upload it to YouTube. Within a few minutes I've combined two blog posts into an interesting and professional looking video. The hard work was in creating the two blog posts in the first place.

Sunday, 2 March 2025

Gray Code Niven Numbers

Let's recall a few facts. A Harshad or Niven number is a number that is divisible by its sum of digits. For example, 21 has a sum of digits of 3 and 3 divides 21 to give 7. Thus 21 is a Niven number, at least in base 10. What about in other bases? Well, in base 7, 21 can be represented as 30 with a sum of digits of 3 again. So 21 is a Niven number in base 7 as well. What about in base 2 where it has a representation of 10101. Again the sum of digits is 3 and thus 21 is also a Niven number in base 2. Of course, 21 is not a Niven number in all bases. In base 8, the number is represented as 25 with a sum of 7 which does not divide into it.


Source

Now I've written about Gray Code in an eponymous post on 18th June 2023 so I won't go into the topic again here. Suffice to say that to generate the Gray Code of a number we convert it to binary and make certain changes to the binary digits. Let's illustrate this by way of the number associated with my diurnal age today, 27727. It's binary representation is 110110001001111 and the Gray Code equivalent is 101101001101000. Now how many 1's are there in the latter. There are seven which corresponds of course to its digit sum. Now 7 divides 27727 because its factorisation is 7 x 17 x 233. So 27727 with its digit sum of 25 is not a Niven number in base 10. Nor is it a Niven number in base 2 where there are nine 1's. However, it is a Gray Code Niven number!

These sorts of numbers caught my attention because of OEIS A344344:


A344344  Starts of runs of 4 consecutive Gray-code Niven numbers (A344341: Gray-code Niven numbers: numbers divisible by the number of 1's in their binary reflected Gray code (A005811)).

Figure 1 shows the results for the four consecutive numbers (permalink):


Figure 1

The initial members of OEIS A344344 are:

1, 6, 30, 126, 510, 543, 783, 903, 2046, 2093, 3773, 3903, 7133, 7743, 8190, 8223, 8703, 10087, 12303, 12543, 14343, 14463, 15423, 15903, 16143, 16263, 20167, 22687, 27727, 30247, 30653, 30783, 32766, 35629, ...

Thursday, 10 October 2024

Binary Complement

I hadn't really heard of the binary complement or 1's complement as it's alternatively called until I came across one of the sequences of which 27583 is a member. The sequence is OEIS A323067:


A323067    Primes whose binary complement (A035327) is a square.

To find the binary complement of a number, simply the invert the 0's and 1's in its binary representation. Let's use 27583 and its binary representation as an example:$$27583_{10}=110101110111111_2$$It's binary complement is:$$1010001000000_2=1584_{10}=72^2$$Thus 27583 does belong in OEIS A323067 and Table 1 shows the members of the sequence up to 40,000 together with their binary complements and square roots:


Table 1: permalink

Notice that powers of 2 plus 1 will all have binary complements equal to 0. All decimal numbers have a 1's complement or binary complement. However, it is not 1-to-1 relationship as different numbers can have the same complement. This is different to the Gray Code that also involves manipulation of the binary digits of a number to produce a new number but involves a 1-to-1 relationship.

The following source gives more information about the topic and its applications:  https://www.tutorialspoint.com/one-s-complement

The Prime Constant And Beyond

A recent Numberphile video informed me of the prime constant which firstly incodes all the primes within an infinitely long sequence of 0's and 1's as shown below:$$01101010001010001010001000001010000010001010001 \dots$$The leading zero corresponds to 1 which is not prime and the next two 1's correspond to 2 and 3 that are prime and so on. The next step is to add a decimal point in front of the leading zero to get:$$0.01101010001010001010001000001010000010001010001 \dots$$This represents a number between 0 and 1 and if we interpret this as a number in base 2 we have a constant that can be expressed as (permalink):$$ \begin{align} \text{Prime Constant } &= \frac{0}{2^1}+\frac{1}{2^2}+\frac{1}{2^3}+\frac{1}{2^4} + \dots \\ \\&\approx 0.414682509851112 \dots \end{align}$$Of course, we could equally well create the non-prime constant by representing every non-prime by a 1 and every prime as a 0. This gives:$$ \text{Non-Prime Constant } \approx 0.585317490148888 \dots$$The prime constant and the non-prime constant of course add to 1. The same idea can be applied to create other constants, for example a Fibonacci constant. The Fibonacci numbers are:$$1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, \dots $$This generates a series of 0's and 1's as follows:$$ 11101001000010000000100000000000010000 \dots$$It can be seen that the three leading 1's are there because 1, 2 and 3 are Fibonacci numbers whereas 4 is not and so it represented by a 0 etc. This gives (permalink):$$ \text{Fibonacci Constant } \approx 0.910278797207866 \dots$$It can thus be seen that all monotonically increasing sequences like the sequence of prime numbers and the sequence of Fibonacci numbers can be represented by a constant between 0 and 1. The base 2 representation is arbitrary but simple but other bases could be used especially to represent more than one sequence. For example, base 4 could be used to represent primes, square-free semiprimes and sphenic numbers. So a 3 could represent a square-free semiprime, a 2 could represent a sphenic number, a 1 could represent a prime and 0 could represent a number that is none of these. This leads to another constant, let's call it the 1-2-3 Factor Constant, where we have a series of 0's, 1's, 2's and 3's:$$011012100210122010102210020013102220 \dots$$These again are converted to a number between 0 and 1:$$0.011012100210122010102210020013102220 \dots$$Interpreting this as a number in base 4 leads to (permalink):$$ \begin{align} \text{1-2-3 Factor Constant } &= \frac{0}{4^1}+\frac{1}{4^2}+\frac{1}{4^3} + \dots \\  \\ &\approx 0.0796530489502776 \dots \end{align}$$There is endless fun to be had in generating these sorts of constants from multiple sequences.

Saturday, 10 August 2024

Radix Economy

In a coffee shop this afternoon, I was reading an interesting article in Quanta Magazine titled How Base 3 Computing Beats Binary. I like the graphic also that began the article and which I've reproduced in Figure 1.


Figure 1: source

The article introduces the notion of "radix economy" that is explained as follows:

The hallmark feature of ternary notation is that it’s ruthlessly efficient. With two binary bits, you can represent four numbers. Two “trits” — each with three different states — allow you to represent nine different numbers. A number that requires 42 bits would need only 27 trits.

If a three-state system is so efficient, you might imagine that a four-state or five-state system would be even more so. But the more digits you require, the more space you’ll need. It turns out that ternary is the most economical of all possible integer bases for representing big numbers.

To see why, consider an important metric that tallies up how much room a system will need to store data. You start with the base of the number system, which is called the radix, and multiply it by the number of digits needed to represent some large number in that radix. For example, the number 100,000 in base 10 requires six digits. Its “radix economy” is therefore 10 × 6 = 60. In base 2, the same number requires 17 digits, so its radix economy is 2 × 17 = 34. And in base 3, it requires 11 digits, so its radix economy is 3 × 11 = 33. For large numbers, base 3 has a lower radix economy than any other integer base.

This Wikipedia article explains it in more formal terms for a number \(N\):$$ \text{radix economy of } N =b \lfloor \log_b(N)+1 \rfloor $$For large \(N\) we can thus write:$$ \begin{align} \text{radix economy of } N &\approx b \log_b(N) \\ &= \frac{b}{ln \,(b)} ln \,(N) \end{align}$$Using the number 123456789 as an example, the radix efficiency for integer bases from 3 to 16 is shown in Figure 2.

Figure 2: base 3 is best

The Quanta article goes on to say that:

In addition to its numerical efficiency, base 3 offers computational advantages. It suggests a way to reduce the number of queries needed to answer questions with more than two possible answers. A binary logic system can only answer “yes” or “no.” So if you’re comparing two numbers, x and y, to find out which is larger, you might first ask the computer “Is x less than y?” If the answer is no, you need a second query: “Is x equal to y?” If the answer is yes, then they’re equal; if the answer is no, then y is less than x. A system using ternary logic can give one of three answers. Because of this, it requires only one query: “Is x less than, equal to, or greater than y?”

And finally, also quoting from the article:

Surprisingly, if you allow a base to be any real number, and not just an integer, then the most efficient computational base is the irrational number e.

The table in Figure 2 looks as shown in Figure 3 when we add "e" to the list of bases.

Figure 3: e is best

Representing numbers using "e" as the number base is the stuff of a future post perhaps but here is a link to how to go about it. 

Saturday, 19 June 2021

Binary Odds and Evens


In my earlier post, titled Odds and Evens, I investigated what happened to decimal numbers when the odd-even recursive process was applied to them. In this process, the sum of a number's odd digits is added to the number and the sum of its even digits subtracted. In those numbers where the sum of the odd and even digits is equal, the number remains unchanged by this process and is termed an attractor, using the nomenclature that I developed. 112 is the first such number and any permutations of the digits of an attractor are also attractors. Thus 112 and 211 are also attractors. Less than 4% of numbers are of this types.

Most numbers are what I termed captives and the process leads them to either an attractor or a vortex. The steps in this process are termed its trajectory and as an example, let's use 5. It's trajectory is 5, 10, 11, 13, 17, 25, 28, 18 because the final number, 18, leads back to 11. The sequence of numbers 11, 13, 17, 25, 28, 18 constitutes a vortex from which there is no escape. On the other hand, 145 has a trajectory of 145, 147, 151, 158, 156 because 156 is an attractor and so no further change is possible. In my last post, titled Attractors, Vortices and Captives, I explored the odd-even decimal universe in more detail.


Figure 1: 150 is an attractor in binary but not in decimal

Once we use binary numbers however, a fundamental difference arises when the odd-even recursive process is applied. There are only 1's and 0's with the former being odd and thus are added while the latter, even though even, don't contribute. Thus there can be no vortices because return to an earlier number is not possible. The process always lead to increasingly bigger numbers and the process will never end. If we don't want the process to go on forever, then some intervention is necessary. One way to terminate the process is to stop when an equal number of 1's and O's is reached. If a number already has this balance then it is an attractor and remains unchanged. This is the approach followed in this post. At the end of this post, I'll suggest another approach.

This is a fundamentally different process. See Figure 1. If applied to decimal numbers, it would mean that a number like 201334 would be an attractor because it has three even digits and three odd digits, even though the sum of the odd digits is 7 and the sum of the even digits is 6. However, the process can be modified to accommodate our binary problem. We could say:

  1. For non-binary number systems, an attractor is defined as a number whose sum of even and odd digits is equal. The odd-even recursive process, as applied to non-binary numbers that are not attractors, is to add the sum of the odd digits and subtract the sum of the even digits so that a new number is generated. This process is repeated until an attractor is reached or the numbers enters a vortex, or endless loop of numbers.

  2. For the binary number system, an attractor is defined as a number with the same number of 1's and 0's. The odd-even recursive process, as applied to binary numbers that are not attractors, is to add the sum of the 1's so that a new number is generated. This process is repeated until an attractor is reached. Vortices are not possible in the binary number system.

Let's use 2149 as an example. As a binary number its trajectory would be:

100001100101, 100001101010, 100001101111, 100001110110

This number has a trajectory of length 3 because 100001110110 is an attractor, having an equal number of 1's and 0's. This attractor in decimal form is 2166. Some numbers take quite a few steps to reach an attractor. 243 is an example of such a number because it takes 59 steps to reach the attractor 527. I've created an algorithm to look at the first 30,000 numbers and I've discovered that the record is set by 15998 with a trajectory of length of 2228 steps, leading to a final number of 33231 (an attractor in the binary number system). Here is a permalink to that program.

In the range between 1 and 30000, attractors total 2353 or 7.84% while there are 27646 captives representing 92.16%.

I mentioned that I'd propose an alternative approach to the odd-even recursive process as applied to binary numbers. This approach involves treating 0's as -1 and 1's as simply 1's. Thus a binary number like 10010110 shown in Figure 1 would still be an attractor but vortices are now possible because of subtraction and these could draw in numbers in the same way that attractors do. The downside is that it treats 0's quite differently than in the higher bases. I'll try to investigate this approach in a future post.

Saturday, 9 May 2020

On the Randomness of Pi's Digits


Much has been written about the randomness of the \(\pi\)'s digits but usually in the context of the decimal number system. Looking at \(\pi\) in terms of the binary number system however, introduces a simplification that can be exploited to investigate its randomness.

The first ten decimal digits of \(\pi\) are 3.141592654 which is represented in binary as:


11.00100100001111110110101010001000100

SageMathCell enables us to examine the first one million decimal digits of \(\pi\), convert these to binary and then graph the cumulative balance between the number of 0's and 1's. The first two 1's are ignored and only the 0's and 1's following the decimal point are considered. Figure 1 shows the result:

Figure 1

Figure 2 shows the code that I used to generate this graph:

Figure 2: permalink

How does this graph compare to that of a sequence of randomly generated 0's and 1's? It's easy enough to undertake this comparison. To this end, I looked at a string of three million randomly generated 0's and 1's because this is approximately the number of binary digits resulting from the conversion of one million decimal digits. The result is shown in Figure 3. Of course, successive repetitions of this algorithm will produce different graphs whereas the graph for \(\pi\) will be always the same. However, it's the general form of the two graphs that I want to compare.

Figure 3: permalink

Figure 4 shows the code that was used to produce this result.

Figure 4: permalink

Not surprisingly, the form of the two graphs is very similar. The point of the exercise is that the conversion of \(\pi\) to binary digits provides an easy visual comparison of its digits with randomly generated 0's and 1's.

ADDENDUM: March 17th 2021

There are of course many interesting facts concerning \(\pi\). Here are some of them:
  • The number pi is literally infinitely long. But the number 123456 doesn’t appear anywhere in the first million digits of \( \pi \). It is a bit shocking because if a million digits of \( \pi \) don’t have the sequence 124356, it definitely is the most unique number. Source.

  • Did you know there is actually an entire language based entirely on \( \pi\)? Called Pilish, the numbers of letters in successive words match the digits in \(\pi\). Mike Keith, a devoted Pilish-lover, even wrote an entire book in Pilish called "Not a Wake." The rules of the language and its variants are described here.

  • Rivers bend to \( \pi\): The way a river meanders is described by its sinuosity; the length of its winding path divided by the distance from the source to the ocean as measured in a straight line. Strange as it may be, the average river has a sinuosity of around 3.14, according to the journal Science. Source.
If you hold a mirror to a circle, it looks like a circle. If you hold a mirror up to 3.14, it spells PIE! See Figure 2.
Figure 2: source

Someone has developed a search engine that can be used to find digit sequences in \( \pi \) in the first \(2 \times 10^0 \) digits of \pi. Figure 3 shows the output if 123456789 is input.


Figure 3

Pressing the next link bring brings up what is shown in Figure 4:


Figure 4
      
The site can also be used to find positions of e, \(\sqrt{2} \) and \(\phi\) where SageMath for example struggles with one million decimal places.

Here is a GeoGebra link that will allows the user to use a slider to display decimal places of \(\pi\).