Examples
Canonical skew binary representations of the numbers from 0 to 15 are shown in following table:Arithmetical operations
The advantage of skew binary is that each increment operation can be done with at most one carry operation. This exploits the fact that . Incrementing a skew binary number is done by setting the only two to a zero and incrementing the next digit from zero to one or one to two. When numbers are represented using a form ofConversion between decimal and skew binary number
To convert from decimal to skew binary number, one can use following formula: Base case: Induction case: Boundaries: To convert from skew binary number to decimal, one can use definition of skew binary number: , where , st. only least significant bit (lsb) is 2.C++ code to convert decimal number to skew binary number
C++ code to convert skew binary number to decimal number
From skew binary representation to binary representation
Given a skew binary number, its value can be computed by a loop, computing the successive values of and adding it once or twice for each such that the th digit is 1 or 2 respectively. A more efficient method is now given, with only bit representation and one subtraction. The skew binary number of the form without 2 and with 1s is equal to the binary number minus . Let represents the digit repeated times. The skew binary number of the form with 1s is equal to the binary number minus .From binary representation to skew binary representation
Similarly to the preceding section, the binary number of the form with 1s equals the skew binary number plus . Note that since addition is not defined, adding corresponds to incrementing the number times. However, is bounded by the logarithm of and incrementation takes constant time. Hence transforming a binary number into a skew binary number runs in time linear in the length of the number.Applications
The skew binary numbers were developed by Eugene Myers in 1983 for a purely functional data structure that allows the operations of the stack abstract data type and also allows efficient indexing into the sequence of stack elements. They were later applied to skew binomial heaps, a variant ofSee also
* Three-valued logic * Redundant binary representation * n-ary Gray codeNotes
{{reflist Number theory Functional programming Computer arithmetic Non-standard positional numeral systems