# Quater-imaginary base

Part of a series on :
Numeral systems :
Place-value notation
Hindu–Arabic numerals
Western Arabic
Eastern Arabic
Bengali
Devanagari
Gujarati
Gurmukhi
Odia
Sinhala
Tamil
Malayalam
Telugu
Kannada
Dzongkha
Tibetan
Balinese
Burmese
Javanese
Khmer
Lao
Mongolian
Sundanese
Thai
East Asian systems
Contemporary
Chinese
Hokkien
Suzhou
Japanese
Korean
Vietnamese
Historic
Counting rods
Tangut
Other systems
History
Ancient
Babylonian
Post-classical
Cistercian
Mayan
Muisca
Pentadic
Quipu
Rumi
Contemporary
Cherokee
Kaktovik (Iñupiaq)
By radix/base
Common radices/bases
2
3
4
5
6
8
10
12
16
20
60
Non-standard radices/bases
Bijective (1)
Signed-digit (balanced ternary)
Mixed (factorial)
Negative
Complex (2i)
Non-integer (φ)
Asymmetric :
Sign-value notation
Non-alphabetic
Aegean
Attic
Aztec
Brahmi
Chuvash
Egyptian
Etruscan
Kharosthi
Prehistoric counting
Proto-cuneiform
Roman
Tally marks
Alphabetic
Abjad
Armenian
Alphasyllabic
Akṣarapallī
Āryabhaṭa
Kaṭapayādi
Coptic
Cyrillic
Geʽez
Georgian
Glagolitic
Greek
Hebrew :
List of numeral systems :
vte :
The quater-imaginary numeral system is a numeral system, first proposed by Donald Knuth in 1960. Unlike standard numeral systems, which use an integer (such as 10 in decimal, or 2 in binary) as their bases, it uses the imaginary number $2i$ (such that $(2i)^{2}=-4$) as its base. It is able to (almost) uniquely represent every complex number using only the digits 0, 1, 2, and 3. Numbers less than zero, which are ordinarily represented with a minus sign, are representable as digit strings in quater-imaginary; for example, the number −1 is represented as "103" in quater-imaginary notation.

## Decomposing the quater-imaginary

In a positional system with base $b$,
$\ldots d_{3}d_{2}d_{1}d_{0}.d_{-1}d_{-2}d_{-3}\ldots$
represents$\dots +d_{3}\cdot b^{3}+d_{2}\cdot b^{2}+d_{1}\cdot b+d_{0}+d_{-1}\cdot b^{-1}+d_{-2}\cdot b^{-2}+d_{-3}\cdot b^{-3}\dots$
In this numeral system, $b=2i$,
and because $(2i)^{2}=-4$, the entire series of powers can be separated into two different series, so that it simplifies to ${\begin{aligned}&[\dots +d_{4}\cdot (-4)^{2}+d_{2}\cdot (-4)^{1}+d_{0}+d_{-2}\cdot (-4)^{-1}+\dots ]\end{aligned}}$ for even-numbered digits (digits that simplify to the value of the digit times a power of -4), and ${\begin{aligned}2i\cdot [\dots +d_{3}\cdot (-4)^{1}+d_{1}+d_{-1}\cdot (-4)^{-1}+d_{-3}\cdot (-4)^{-2}+\dots ]\end{aligned}}$ for those digits that still have an imaginary factor. Adding these two series together then gives the total value of the number.
Because of the separation of these two series, the real and imaginary parts of complex numbers are readily expressed in base −4 as $\ldots d_{4}d_{2}d_{0}.d_{-2}\ldots$ and $2\cdot (\ldots d_{5}d_{3}d_{1}.d_{-1}d_{-3}\ldots )$ respectively.

## Converting from quater-imaginary

Powers of 2i :
| k | (2i)$^k$ |
| −5 | −i/32 |
| −4 | 1/16 |
| −3 | i/8 |
| −2 | −1/4 |
| −1 | −i/2 |
| 0 | 1 |
| 1 | 2i |
| 2 | −4 |
| 3 | −8i |
| 4 | 16 |
| 5 | 32i |
| 6 | −64 |
| 7 | −128i |
| 8 | 256 |
To convert a digit string from the quater-imaginary system to the decimal system, the standard formula for positional number systems can be used. This says that a digit string $\ldots d_{3}d_{2}d_{1}d_{0}$ in base b can be converted to a decimal number using the formula
    $\cdots +d_{3}\cdot b^{3}+d_{2}\cdot b^{2}+d_{1}\cdot b+d_{0}$
For the quater-imaginary system, $b=2i$.
Additionally, for a given string $d$ in the form $d_{w-1},d_{w-2},\dots d_{0}$, the formula below can be used for a given string length $w$ in base $b$
    $Q2D_{w}{\vec {d}}\equiv \sum _{k=0}^{w-1}d_{k}\cdot b^{k}$

### Example

To convert the string $1101_{2i}$ to a decimal number, fill in the formula above:
    $1\cdot (2i)^{3}+1\cdot (2i)^{2}+0\cdot (2i)^{1}+1\cdot (2i)^{0}=-8i-4+0+1=-3-8i$
Another, longer example: $1030003_{2i}$ in base 10 is
    $1\cdot (2i)^{6}+3\cdot (2i)^{4}+3\cdot (2i)^{0}=-64+3\cdot 16+3=-13$

## Converting into quater-imaginary

It is also possible to convert a decimal number to a number in the quater-imaginary system. Every complex number (every number of the form a+bi) has a quater-imaginary representation. Most numbers have a unique quater-imaginary representation, but just as 1 has the two representations 1 = 0.9 in decimal notation, so, because of 0.0001$_{2i}$ = ⁠1/15⁠, the number ⁠1/5⁠ has the two quater-imaginary representations 0.0003$_{2i}$ = 3·⁠1/15⁠ = ⁠1/5⁠ = 1 + 3·⁠–4/15⁠ = 1.0300$_{2i}$.
To convert an arbitrary complex number to quater-imaginary, it is sufficient to split the number into its real and imaginary components, convert each of those separately, and then add the results by interleaving the digits. For example, since −1+4i is equal to −1 plus 4i, the quater-imaginary representation of −1+4i is the quater-imaginary representation of −1 (namely, 103) plus the quater-imaginary representation of 4i (namely, 20), which gives a final result of −1+4i = 123$_{2i}$.
To find the quater-imaginary representation of the imaginary component, it suffices to multiply that component by 2i, which gives a real number; then find the quater-imaginary representation of that real number, and finally shift the representation by one place to the right (thus dividing by 2i). For example, the quater-imaginary representation of 6i is calculated by multiplying 6i × 2i = −12, which is expressed as 300$_{2i}$, and then shifting by one place to the right, yielding: 6i = 30$_{2i}$.
Finding the quater-imaginary representation of an arbitrary real integer number can be done manually by solving a system of simultaneous equations, as shown below, but there are faster methods for both real and imaginary integers, as shown in the negative base article.

### Example: Real number

As an example of an integer number we can try to find the quater-imaginary counterpart of the decimal number 7 (or 7$_{10}$ since the base of the decimal system is 10). Since it is hard to predict exactly how long the digit string will be for a given decimal number, it is safe to assume a fairly large string. In this case, a string of six digits can be chosen. When an initial guess at the size of the string eventually turns out to be insufficient, a larger string can be used.
To find the representation, first write out the general formula, and group terms:
    ${\begin{aligned}7_{10}&=d_{0}+d_{1}\cdot b+d_{2}\cdot b^{2}+d_{3}\cdot b^{3}+d_{4}\cdot b^{4}+d_{5}\cdot b^{5}\\&=d_{0}+2id_{1}-4d_{2}-8id_{3}+16d_{4}+32id_{5}\\&=d_{0}-4d_{2}+16d_{4}+i(2d_{1}-8d_{3}+32d_{5})\\\end{aligned}}$
Since 7 is a real number, it is allowed to conclude that d$_1$, d$_3$ and d$_5$ should be zero. Now the value of the coefficients d$_0$, d$_2$ and d$_4$, must be found. Because d$_0$ − 4 d$_2$ + 16 d$_4$ = 7 and because—by the nature of the quater-imaginary system—the coefficients can only be 0, 1, 2 or 3 the value of the coefficients can be found. A possible configuration could be: d$_0$ = 3, d$_2$ = 3 and d$_4$ = 1. This configuration gives the resulting digit string for 7$_{10}$.
    $7_{10}=010303_{2i}=10303_{2i}.$

### Example: Imaginary number

Finding a quater-imaginary representation of a purely imaginary integer number ∈ iZ is analogous to the method described above for a real number. For example, to find the representation of 6i, it is possible to use the general formula. Then all coefficients of the real part have to be zero and the complex part should make 6. However, for 6i it is easily seen by looking at the formula that if d$_1$ = 3 and all other coefficients are zero, we get the desired string for 6i. That is:
    ${\begin{aligned}6i_{10}=30_{2i}\end{aligned}}$

### Another conversion method

For real numbers the quater-imaginary representation is the same as negative quaternary (base −4). A complex number x+iy can be converted to quater-imaginary by converting x and y/2 separately to negative quaternary. If both x and y are finite binary fractions we can use the following algorithm using repeated Euclidean division:
For example: 35+23i=121003.2$_{2i}$

## Radix point "."

A radix point in the decimal system is the usual . (dot) which marks the separation between the integer part and the fractional part of the number. In the quater-imaginary system a radix point can also be used. For a digit string $\dots d_{5}d_{4}d_{3}d_{2}d_{1}d_{0}.d_{-1}d_{-2}d_{-3}\dots$ the radix point marks the separation between non-negative and negative powers of b. Using the radix point the general formula becomes:
    $d_{5}b^{5}+d_{4}b^{4}+d_{3}b^{3}+d_{2}b^{2}+d_{1}b+d_{0}+d_{-1}b^{-1}+d_{-2}b^{-2}+d_{-3}b^{-3}$
or
    ${\begin{aligned}32id_{5}+16d_{4}-8id_{3}-4d_{2}+2id_{1}+d_{0}+{\frac {1}{2i}}d_{-1}+{\frac {1}{-4}}d_{-2}+{\frac {1}{-8i}}d_{-3}\\=32id_{5}+16d_{4}-8id_{3}-4d_{2}+2id_{1}+d_{0}-{\frac {i}{2}}d_{-1}-{\frac {1}{4}}d_{-2}+{\frac {i}{8}}d_{-3}\end{aligned}}$

### Example

If the quater-imaginary representation of the complex unit i has to be found, the formula without radix point will not suffice. Therefore, the above formula should be used. Hence:
    ${\begin{aligned}i&=32id_{5}+16d_{4}-8id_{3}-4d_{2}+2id_{1}+d_{0}+{\frac {1}{2i}}d_{-1}+{\frac {1}{-4}}d_{-2}+{\frac {1}{-8i}}d_{-3}\\&=i(32d_{5}-8d_{3}+2d_{1}-{\frac {1}{2}}d_{-1}+{\frac {1}{8}}d_{-3})+16d_{4}-4d_{2}+d_{0}-{\frac {1}{4}}d_{-2}\\\end{aligned}}$
for certain coefficients d$_k$. Then because the real part has to be zero: d$_4$ = d$_2$ = d$_0$ = d$_{−2}$ = 0. For the imaginary part, if d$_5$ = d$_3$ = d$_{−3}$ = 0 and when d$_1$ = 1 and d$_{−1}$ = 2 the digit string can be found. Using the above coefficients in the digit string the result is:
    $i=10.2_{2i}.$

## Addition and subtraction

It is possible to add and subtract numbers in the quater-imaginary system. In doing this, there are two basic rules that have to be kept in mind:
* Whenever a number exceeds 3, subtract 4 and "carry" −1 two places to the left.
* Whenever a number drops below 0, add 4 and "carry" +1 two places to the left.
Or for short: "If you add four, carry +1. If you subtract four, carry −1". This is the opposite of normal long addition, in which a "carry" in the current column requires adding 1 to the next column to the left, and a "borrow" requires subtracting. In quater-imaginary arithmetic, a "carry" subtracts from the next-but-one column, and a "borrow" adds.

### Example: Addition

Below are two examples of adding in the quater-imaginary system:
In the first example we start by adding the two 1s in the first column (the "ones' column"), giving 2. Then we add the two 3s in the second column (the "2is column"), giving 6; 6 is greater than 3, so we subtract 4 (giving 2 as the result in the second column) and carry −1 into the fourth column. Adding the 0s in the third column gives 0; and finally adding the two 1s and the carried −1 in the fourth column gives 1.
In the second example we first add 3+1, giving 4; 4 is greater than 3, so we subtract 4 (giving 0) and carry −1 into the third column (the "−4s column"). Then we add 2+0 in the second column, giving 2. In the third column, we have 0+0+(−1), because of the carry; −1 is less than 0, so we add 4 (giving 3 as the result in the third column) and "borrow" +1 into the fifth column. In the fourth column, 1+1 is 2; and the carry in the fifth column gives 1, for a result of $12320_{2i}$.

### Example: Subtraction

Subtraction is analogous to addition in that it uses the same two rules described above. Below is an example:
In this example we have to subtract $1011_{2i}$ from $1102_{2i}$. The rightmost digit is 2−1 = 1. The second digit from the right would become −1, so add 4 to give 3 and then carry +1 two places to the left. The third digit from the right is 1−0 = 1. Then the leftmost digit is 1−1 plus 1 from the carry, giving 1. This gives a final answer of $1131_{2i}$.

## Multiplication

For long multiplication in the quater-imaginary system, the two rules stated above are used as well. When multiplying numbers, multiply the first string by each digit in the second string consecutively and add the resulting strings. With every multiplication, a digit in the second string is multiplied with the first string. The multiplication starts with the rightmost digit in the second string and then moves leftward by one digit, multiplying each digit with the first string. Then the resulting partial products are added where each is shifted to the left by one digit. An example:
This corresponds to a multiplication of $(9-8i)\cdot (29+4i)=293-196i$.

## Tabulated conversions

Below is a table of some decimal and complex numbers and their quater-imaginary counterparts.
| Base 10 | Base 2i |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 10300 |
| 5 | 10301 |
| 6 | 10302 |
| 7 | 10303 |
| 8 | 10200 |
| 9 | 10201 |
| 10 | 10202 |
| 11 | 10203 |
| 12 | 10100 |
| 13 | 10101 |
| 14 | 10102 |
| 15 | 10103 |
| 16 | 10000 |
| Base 10 | Base 2i |
| −1 | 103 |
| −2 | 102 |
| −3 | 101 |
| −4 | 100 |
| −5 | 203 |
| −6 | 202 |
| −7 | 201 |
| −8 | 200 |
| −9 | 303 |
| −10 | 302 |
| −11 | 301 |
| −12 | 300 |
| −13 | 1030003 |
| −14 | 1030002 |
| −15 | 1030001 |
| −16 | 1030000 |
| Base 10 | Base 2i |
| 1i | 10.2 |
| 2i | 10.0 |
| 3i | 20.2 |
| 4i | 20.0 |
| 5i | 30.2 |
| 6i | 30.0 |
| 7i | 103000.2 |
| 8i | 103000.0 |
| 9i | 103010.2 |
| 10i | 103010.0 |
| 11i | 103020.2 |
| 12i | 103020.0 |
| 13i | 103030.2 |
| 14i | 103030.0 |
| 15i | 102000.2 |
| 16i | 102000.0 |
| Base 10 | Base 2i |
| −1i | 0.2 |
| −2i | 1030.0 |
| −3i | 1030.2 |
| −4i | 1020.0 |
| −5i | 1020.2 |
| −6i | 1010.0 |
| −7i | 1010.2 |
| −8i | 1000.0 |
| −9i | 1000.2 |
| −10i | 2030.0 |
| −11i | 2030.2 |
| −12i | 2020.0 |
| −13i | 2020.2 |
| −14i | 2010.0 |
| −15i | 2010.2 |
| −16i | 2000.0 |

## Examples

Below are some other examples of conversions from decimal numbers to quater-imaginary numbers.
    $5=16+(3\cdot -4)+1=10301_{2i}$
    $i=2i+2\left(-{\frac {1}{2}}i\right)=10.2_{2i}$
    $7{\frac {3}{4}}-7{\frac {1}{2}}i=1(16)+1(-8i)+2(-4)+1(2i)+3\left(-{\frac {1}{2}}i\right)+1\left(-{\frac {1}{4}}\right)=11210.31_{2i}$

## Z-order curve

The representation
    $z=\sum _{k\geq n}z_{k}\cdot (2i)^{-k}$
of an arbitrary complex number $z\in \mathbb {C}$ with $z_{k}\in \{0,1,2,3\}$ gives rise to an injective mapping
    $\textstyle {\begin{array}{llcl}\varphi \colon &\mathbb {C} &\to &\mathbb {R} \\&\sum _{k\geq n}z_{k}\cdot (2i)^{-k}&\mapsto &\sum _{k\geq n}z_{k}\cdot r^{-k}\\\end{array}}$
with some suitable $r\in \mathbb {Z}$. Here $r=4$ cannot be taken as base because of
    $\textstyle \sum _{k>0}3\cdot (2i)^{-k}={\tfrac {-3-6i}{5}}\;\;\;\;\neq \;\;\;\;1=\sum _{k>0}3\cdot 4^{-k}.$
The image $\varphi (\mathbb {C} )\subset \mathbb {R}$ is a Cantor set which allows to linearly order $\mathbb {C}$ similar to a Z-order curve. Since the image is disconnected, $\varphi$ is not continuous.