Non-adjacent form
From Wikipedia, the free encyclopedia
| Numeral systems by culture | |
|---|---|
| Hindu-Arabic numerals | |
| Western Arabic Eastern Arabic Khmer |
Indian family Brahmi Thai |
| East Asian numerals | |
| Chinese Japanese |
Korean |
| Alphabetic numerals | |
| Abjad Armenian Cyrillic Ge'ez |
Hebrew Ionian/Greek Sanskrit |
| Other systems | |
| Attic Etruscan Urnfield Roman |
Babylonian Egyptian Mayan |
| List of numeral system topics | |
| Positional systems by base | |
| Decimal (10) | |
| 2, 4, 8, 16, 32, 64 | |
| 3, 9, 12, 24, 30, 36, 60, more… | |
The non-adjacent form (NAF) of a number is a unique signed-digit representation. Like the name suggests, non-zero values cannot be adjacent. For example:
- (0 1 1 1) = 4 + 2 + 1 = 7
- (1 0 −1 1) = 8 − 2 + 1 = 7
- (1 −1 1 1) = 8 − 4 + 2 + 1 = 7
- (1 0 0 −1) = 8 − 1 = 7
All are valid signed-digit representations of 7, but only the final representation (1 0 0 −1) is in NAF.
There are several algorithms for obtaining the NAF representation of a value given in binary. One such is the following method using repeated division:
- Input: E = (em − 1 em − 2 ··· e1 e0)10
- Output: E = (zm zm − 1 ··· z1 z0)NAF
- i ← 0
- while E > 0 do
- if E is odd then
- zi ← 2 − (E mod 4)
- else
- zi ← 0
- E ← (E − zi)/2
- i ← i + 1
- if E is odd then
- return z
NAF assures a unique representation of an integer, but the main benefit of it is that the Hamming weight of the value will be minimal. For regular binary representations of values, half of all bits will be non-zero, on average, but with NAF this drops to only one-third of all digits.
Obviously, at most half of the digits are non-zero, which was the reason it was introduced by G.W. Reitweisner in 1960 for speeding up early multiplication algorithms.
Because every non-zero value has to be adjacent to two 0's, the NAF representation can be implemented such that it only takes a maximum of m + 1 bits for a value that would normally be represented in binary with m bits.
The properties of NAF make it useful in various algorithms, especially some in cryptography, e.g., for reducing the number of multiplications needed for performing an exponentiation. In the algorithm exponentiation by squaring the number of multiplications depends on the number of non-zero bits. If the exponent here is given in NAF form a digit value 1 implies a multiplication by the base, and a digit value -1 by its reciprocal.