Rice coding: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Updated in line with Julia and also added basic codings for k= 4.) |
(→{{header|Wren}}: Oops!) |
||
Line 177: | Line 177: | ||
} |
} |
||
System.print("Basic Rice coding:") |
System.print("Basic Rice coding (k = 2):") |
||
for (i in 0..10) { |
for (i in 0..10) { |
||
var res = Rice.encode(i, 2) |
var res = Rice.encode(i, 2) |
||
Line 183: | Line 183: | ||
} |
} |
||
System.print("\nExtended Rice coding:") |
System.print("\nExtended Rice coding (k == 2):") |
||
for (i in -10..10) { |
for (i in -10..10) { |
||
var res = Rice.encodeEx(i, 2) |
var res = Rice.encodeEx(i, 2) |
||
Line 197: | Line 197: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Basic Rice coding: |
Basic Rice coding (k = 2): |
||
0 -> |
0 -> 000 -> 0 |
||
1 -> |
1 -> 001 -> 1 |
||
2 -> |
2 -> 010 -> 2 |
||
3 -> |
3 -> 011 -> 3 |
||
4 -> |
4 -> 1000 -> 4 |
||
5 -> |
5 -> 1001 -> 5 |
||
6 -> |
6 -> 1010 -> 6 |
||
7 -> |
7 -> 1011 -> 7 |
||
8 -> |
8 -> 11000 -> 8 |
||
9 -> |
9 -> 11001 -> 9 |
||
10 -> |
10 -> 11010 -> 10 |
||
Extended Rice coding: |
Extended Rice coding (k == 2): |
||
-10 -> |
-10 -> 1111011 -> -10 |
||
-9 -> |
-9 -> 1111001 -> -9 |
||
-8 -> |
-8 -> 111011 -> -8 |
||
-7 -> |
-7 -> 111001 -> -7 |
||
-6 -> |
-6 -> 11011 -> -6 |
||
-5 -> |
-5 -> 11001 -> -5 |
||
-4 -> |
-4 -> 1011 -> -4 |
||
-3 -> |
-3 -> 1001 -> -3 |
||
-2 -> |
-2 -> 011 -> -2 |
||
-1 -> |
-1 -> 001 -> -1 |
||
0 -> |
0 -> 000 -> 0 |
||
1 -> |
1 -> 010 -> 1 |
||
2 -> |
2 -> 1000 -> 2 |
||
3 -> |
3 -> 1010 -> 3 |
||
4 -> |
4 -> 11000 -> 4 |
||
5 -> |
5 -> 11010 -> 5 |
||
6 -> |
6 -> 111000 -> 6 |
||
7 -> |
7 -> 111010 -> 7 |
||
8 -> |
8 -> 1111000 -> 8 |
||
9 -> |
9 -> 1111010 -> 9 |
||
10 -> |
10 -> 11111000 -> 10 |
||
Basic Rice coding (k == 4): |
Basic Rice coding (k == 4): |