The Cantor sequence is similar to the Cantor set but deals with integers. To construct it, start with the natural numbers , writing them in ternary notation as . Construct a binary sequence : if in ternary has only 0s or 2s, let ; otherwise let . This gives .
This Demonstration shows the Cantor sequence for the numbers from 0 to . You can scale and scan the sequence. The pixel colors code the digits: red for -1, green for 0, blue for 1, and gray for 2. Yellow mesh lines mark the bits of the Cantor sequence and purple mesh lines mark the selected position in the selected range. The positions are given as fractions and present the subrange of 81 digit values of integers for the scan.
The Cantor set is constructed iteratively; starting with the closed unit interval , the open middle third is taken out, leaving the two closed intervals and . Then the middle thirds of those two intervals are taken out, leaving four intervals of length , and so on. The Cantor set is the limit (or intersection) of all such sets.
Here is a way to look at the Cantor set in terms of the base 3 (ternary) representation of numbers. In the unit interval numbers in base 3 have the form , where the are all possible combinations of the digits 0, 1 or 2. The numbers in the middle third of start with 0.1; the numbers in the middle thirds of and start with 0.01 and 0.21. In general, numbers in a middle third have the digit 1 somewhere in their ternary expansion. In other words, the Cantor set consists of numbers that only have 0 or 2 as ternary digits. Replacing the 2s with 1s in those expansions gives a representation of the Cantor set using binary numbers.