Rice coding: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Updated in line with Julia and also added basic codings for k= 4.)
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 -> 0000 -> 0
0 -> 000 -> 0
1 -> 0001 -> 1
1 -> 001 -> 1
2 -> 0010 -> 2
2 -> 010 -> 2
3 -> 0011 -> 3
3 -> 011 -> 3
4 -> 10000 -> 4
4 -> 1000 -> 4
5 -> 10001 -> 5
5 -> 1001 -> 5
6 -> 10010 -> 6
6 -> 1010 -> 6
7 -> 10011 -> 7
7 -> 1011 -> 7
8 -> 110000 -> 8
8 -> 11000 -> 8
9 -> 110001 -> 9
9 -> 11001 -> 9
10 -> 110010 -> 10
10 -> 11010 -> 10


Extended Rice coding:
Extended Rice coding (k == 2):
-10 -> 11110011 -> -10
-10 -> 1111011 -> -10
-9 -> 11110001 -> -9
-9 -> 1111001 -> -9
-8 -> 1110011 -> -8
-8 -> 111011 -> -8
-7 -> 1110001 -> -7
-7 -> 111001 -> -7
-6 -> 110011 -> -6
-6 -> 11011 -> -6
-5 -> 110001 -> -5
-5 -> 11001 -> -5
-4 -> 10011 -> -4
-4 -> 1011 -> -4
-3 -> 10001 -> -3
-3 -> 1001 -> -3
-2 -> 0011 -> -2
-2 -> 011 -> -2
-1 -> 0001 -> -1
-1 -> 001 -> -1
0 -> 0000 -> 0
0 -> 000 -> 0
1 -> 0010 -> 1
1 -> 010 -> 1
2 -> 10000 -> 2
2 -> 1000 -> 2
3 -> 10010 -> 3
3 -> 1010 -> 3
4 -> 110000 -> 4
4 -> 11000 -> 4
5 -> 110010 -> 5
5 -> 11010 -> 5
6 -> 1110000 -> 6
6 -> 111000 -> 6
7 -> 1110010 -> 7
7 -> 111010 -> 7
8 -> 11110000 -> 8
8 -> 1111000 -> 8
9 -> 11110010 -> 9
9 -> 1111010 -> 9
10 -> 111110000 -> 10
10 -> 11111000 -> 10


Basic Rice coding (k == 4):
Basic Rice coding (k == 4):