A folding function is a function that maps the integers onto the nonnegative integers . This type of function arises naturally in situations where it is desirable to remove the sign of an integer (for example, to show that , or when encoding signed integers using a technique that works only for nonnegative integers (for example, in data compression).
The usual function folding function is given by
(1)
|
with inverse
(2)
|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |||||||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
computes the mapping shown above.
Another variant may be defined by
(3)
|
with inverse
(4)
|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ||||||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
computes the mapping shown above.